Type Properties
Up to now, you have been working with instance properties. Whenever you create a new instance of a type, that instance gets its own properties that are distinct from other instances of that type. Instance properties are useful for storing and computing values on an instance of a type, but what about values that belong to the type itself?
You can also define type properties. These are properties that are universal to the type – the values in these properties will be shared across all of the type’s instances. These properties store information that will be the same across all instances. For example, all instances of a Square type will have exactly four sides, so the number of sides for Square might be stored in a type ...
Get Swift Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.