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 that external resources 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 is an initializer. In ...
Get Mastering Swift 3 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.