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.

Structs

Structs

- [Instructor] UIKit is strongly dependent on classes, and your coding will be heavy with classes because of that. SwiftUI is based not on classes but structs. So, you might want to know a bit more about structs before you start to look at SwiftUI. Structs and classes can look a lot alike. Take a look at this struct and class in the playground in the exercise files. Except for the word struct and class, they look the same. Below them, they initialize the same as well. However, here's the first difference: you don't need an initializer for a struct, while you do for a class. If I delete the init in the struct, I get no error. If I delete the one in the class, I get an error. Structs have an implicit initializer of all properties. You can override it and write your own initializer. So, I'm going to do a Command + Z here, twice, and then I'm going to rewrite the PizzaStruct one, so it's only topping. And I'll change the size to 10. That, of course, means there's an extra argument here…

Contents