Great work! We’ve expanded on our understanding of structures and properties and learned about access control, adding a lot of useful tools to our Swift toolbelt. Here are the key points we covered in this lesson:
- The boundaries for access control are modules, source files, and
- Public is the most permissive and allows access between modules. (useful for SDKs and frameworks)
- Internal is the default level and allows access anywhere within a module.
- File private allows access within a source file.
- Private can only be used within the scope of a
struct. (least permissive)
- Private properties are defined using the
- Memberwise initializers can’t access private properties, so you need to use default values, make them optional, or use the init method.
- Private methods use the same syntax as private properties and can only be called within the scope of the
structthat defines them.
- Computed properties aren’t stored values, rather they are derived from other stored properties.
- Can be read-only. (only have getter method)
- Can set them, in which case you change the underlying properties from which they are derived.
- Property observers are built in methods that get called when properties are set.
- didSet gives us the old value.
- willSet gives us the new value.
- Properties can have a more restricted access level to set vs. get.
- Type properties are defined independently from any particular instance of a structure.
Take this course for free