Properties and Access Control
Lesson 1 of 1
  1. 1
    In this lesson, we will explore some special types of properties we can use in structures as well as how access control works in Swift, and how to apply it in the context of structures. Let’s beg…
  2. 2
    Public We’ll start with public, the most open level, which grants access to a property or method from inside or outside the module. Relating it to the company analogy, since modules are compani…
  3. 3
    As we learned in the previous exercise, private is the most restrictive level of access control and can be applied to properties or methods. When we make a property private, we make it so that its …
  4. 4
    There are some cases in which we may not want to expose methods outside of the scope of the structure such as when the method might access or modify some sensitive data. For those cases, we can use…
  5. 5
    There is another way we can access private properties inside of a structure: computed properties. Computed properties are a special type of property that don’t actually store a value directly, rath…
  6. 6
    In addition to getting computed properties, there may be cases where it would be convenient to set the computed property as well. Recall that computed properties don’t store values directly, so we’…
  7. 7
    Another built-in feature of properties we might find useful is property observers. If access control is a lockset for our properties, property observers are the security cameras. Specifically, prop…
  8. 8
    Oftentimes, we find ourselves being more concerned with data being changed and not so concerned about who can read it. When this is the case, it is possible to implement a private setter. A private…
  9. 9
    Up until this point, we have always associated properties with an instance of a struct. However, it is also possible to define a property that is associated directly with the struct itself. Such …
  10. 10
    When writing a struct, class, or enum it may be helpful to divide the code into several different sections. By using an extension, you can continue writing the definition of a struct, class, o…
  11. 11
    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…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo