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 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
Download course materials from Github
Previous: Demo Next: Quiz: Structs & Classes