3.6 Wrap-Up
In this chapter, you created a class and objects of that class, then called methods of those objects to perform useful actions, such as depositing money into or withdrawing money from an Account.
We introduced the access modifiers public, internal and private, and you defined a public class, with public properties, a public initializer and public methods, that could be reused in other apps.
You defined read/write stored properties to maintain data for each object of a class. You also created a read/write property with a private set so that the property’s setter could be used only within class Account, not by the class’s clients. This enabled the class to control all updates to the balance internally (where they could be validated) and to prevent clients from accidentally modifying the Account’s balance. We discussed computed properties that operate on a class’s other properties, but do not themselves store any data.
You used keyword init to create an initializer that allowed a client to specify the initial values for a new Account object’s properties. We discussed that Swift requires an initializer call for every new object that’s created. We also discussed the default initializer that the compiler creates for a class that does not explicitly define one. You defined and called methods to operate on the class’s properties.
We discussed the differences between calling functions, methods and initializers. You learned that classes are reference types, and we presented various differences between value types and reference types. All non-class types in Swift are value types. Finally, we discussed access modifiers in more detail.
In Chapter 4, we discuss Swift’s conditional statements and loop statements, which specify the order in which a program’s actions are performed. We also present Swift’s arithmetic assignment operators, increment and decrement operators, and logical operators.