Declaring new convenience initializers with extensions

So far, we have always worked with one specific type of initializer for all the classes: designated and initializers. These are the primary initializers for a class in Swift, and they make sure that all the properties are initialized. In fact, every class must have at least one designated initializer. However, it is important to note that a class can satisfy this requirement by inheriting a designated initializer from its superclass.

There is another type of initializer known as convenience initializer that acts as a secondary initializer and always ends up calling a designated initializer. Convenience initializers are optional, so any class can declare one or more convenience initializers ...

Get Swift 3 ObjectOriented Programming - Second 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.