Chapter 5. Demystifying initializers

This chapter covers

  • Demystifying Swift’s initializer rules
  • Understanding quirks of struct initializers
  • Understanding complex initializer rules when subclassing
  • How to keep the number of initializers low when subclassing
  • When and how to work with required initializers

As a Swift developer, initializing your classes and structs are one of the core fundamentals that you have been using.

But initializers in Swift are not intuitive. Swift offers memberwise initializers, custom initializers, designated initializers, convenience initializers, required initializers, and I didn’t even mention the optional initializers, failable initializers, and throwing initializers. Frankly, it can get bewildering sometimes. ...

Get Swift in Depth 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.