Conclusion
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 aninit
method for a struct, but you did for a class. - You implemented a
showImage
method, using theisPublicDomain
property to determine whether to useMuseumObjectView
orSFSafariViewController(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.