You’ve learned a lot about structs and classes in this lesson:
You defined a MuseumObject type with properties and instantiated some objects. You didn’t have to define an init method for a struct, but you did for a class.
You implemented a showImage method, using the isPublicDomain property to determine whether to use MuseumObjectView or SFSafariViewController(url:).
With one art object in the public domain and one not in the public domain, you called showImage().
You demonstrated two other differences between structs and classes: First, structs are value types, while classes are reference types. Secondly, if a struct method modifies a struct object, you must mark it as mutating.
Finally, you hid a property by making it private and saw how this affects initialization for structs and classes.
See forum comments
This content was released on Oct 17 2023. The official support period is 6-months
from this date.
Summary for structs and classes.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.