Conclusion
You’ve learned a lot about structs and classes in this lesson:
- You defined a
MuseumObjecttype with properties and instantiated some objects. You didn’t have to define aninitmethod for a struct, but you did for a class. - You implemented a
showImagemethod, using theisPublicDomainproperty to determine whether to useMuseumObjectVieworSFSafariViewController(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
privateand saw how this affects initialization for structs and classes.