17 Initialization

Initialization is the operation of setting up an instance of a type. It entails giving each stored property an initial value and may involve other preparatory work. After this process, the instance is prepared and available to use.

The types that you have been creating up to this point have all been created in more or less the same way. The values for the properties were either given default stored values or were computed on demand. Initialization was not customized, and it was not particularly considered.

It is very common to want control over how an instance of a type is created. For example, it would be ideal for the instance to have all of the correct values in its properties immediately. Previously, you ...

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.