O'Reilly logo

iOS® 8 for Programmers: An App-Driven Approach with Swift™, Third Edition by Abbey Deitel, Harvey M. Deitel, Paul J. Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.5.3 Model Initializer and synchronize Method

Figure 4.17 defines class Model’s initializer. Swift does not provide default values for a class’s properties—you must initialize them before they’re used. Lines 17–18 (Fig. 4.16) explicitly specify default values. Each class you declare can optionally provide one or more initializers that can be used to initialize a new object of a class. In fact, Swift requires an initializer call for every object that’s created, so this is the ideal point to initialize an object’s properties. For a class that does not explicitly define any initializers, the compiler defines a default initializer (with no parameters) that initializes the class’s properties to the default values specified in their definitions. Initializers ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required