Initialization Going Forward

How am I going to remember all this? We hear you. Initialization in Swift is a very defined process with a lot of rules. Thankfully, the compiler will remind you of what you need to do in order to comply and write a valid initializer. Rather than memorizing all of the rules to initialization, it is useful to think of Swift initialization in terms of value types and classes.

For value types, such as structs, initialization is principally responsible for ensuring that all of the instance’s stored properties have been initialized and given appropriate values. This statement is true for classes as well, but initialization is a bit more complicated in this case.

Initialization for classes can be thought ...

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