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.

Recursive structs

Recursive structs

- [Instructor] For some new functionality in SwiftUI and UIkit for iOS 14, you'll be organizing your model in recursive structs. If you're not familiar with them, let's have a look at how to make one and how to use them. Recursion's best definition is just to see the definition of recursion. It is an object or function that uses itself in its definition. It is at the core of any hierarchical data structure. A recursive struct defines itself pretty much like this. Struct MyModel, which is a property, which I'll call children of MyModel, so it's essentially making itself. Now, I'm going to make this also optional and I'm going to make it start as nil. So when the children are nil, I have no more children and this lets me go through this over and over again so I can have more children to this and those children can have children until I have a case of nil when I'm at the end here. Now, this itself isn't very…

Contents