Class Initialization

The general syntax for initialization in classes looks very similar to initialization in value types. However, there are some different rules for classes that must be observed. These additional rules are mainly due to the fact that classes can inherit from other classes, which adds some complexity to initialization.

In particular, classes add the concepts of designated and convenience initializers. An initializer on a class is either one or the other. Designated initializers are responsible for making sure that an instance’s properties all have values before initialization completes, thus making the instance ready to use. Convenience initializers supplement designated initializers by calling across a class to its designated ...

Get Swift Programming: The Big Nerd Ranch Guide, 3rd Edition 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.