Properties
Properties associate values with a class or a structure. There are two types of properties:
- Stored properties: These will store variable or constant values as part of an instance of a class or structure. Stored properties can also have property observers that can monitor the property for changes and respond with custom actions when the value of the property changes.
- Computed properties: These do not store a value themselves but instead retrieve and possibly set other properties. The value returned by a computed property can also be calculated when it is requested.
Stored properties
A stored property is a variable or constant that is stored as part of an instance of a class or structure. These are defined with the var
and let
keywords, just like normal variables and constants. In the following code, we will create a structure named MyStruct
and a class named MyClass
. The structure and the class both contain two stored properties, c
and v
. The...