From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Recursion and changing UIViews

Recursion and changing UIViews

From the course: iOS Development Tips

Recursion and changing UIViews

- [Instructor] One powerful, yet sometimes rifely-feared programming technique is recursion. Many do not even use it. Some don't know what it is, but when working with hierarchies, you really have to use it. Let's take a look at recursion and apply it to a common UI case where you need it. Download and open the exercise file. I put a playground in here to show you some simple recursion. Head into the recursion playground, close up some things so you've got some space, and you see here my favorite definition of recursion, which is See Recursion. That's all it is; it's recalling yourself. The most basic recursion is right here. I just take a function and I call it in itself. As you can see, Xcode's not happy with this and will actually warn you if you find a situation like this where it just keeps calling itself. Things like this will run forever, but in reality, what's gonna happen is it'll run until you run out of memory or out of range of your type. In any case, one way or another…

Contents