Custom initializers

Initializers are called when we initialize a new instance of a particular type (class or structure). Initialization is the process of preparing an instance for use. The initialization process can include setting initial values for stored properties, verifying resources, such as web services, files, and so on are available, or setting up the UI properly. Initializers are generally used to ensure that the instance of the class or structure is properly initialized prior to first use.

Initializers are special methods that are used to create a new instance of a type. We define an initializer exactly as we would define other methods, but we must use the init keyword as the name of the initializer to tell the compiler that this method ...

Get Swift: Developing iOS Applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.