Convenience Initializers
Prefer convenience initializers whenever there’s a simpler, easier, or more convenient way to create new instances than laying out memberwise components. Convenience initializers create type shortcuts that illuminate your coding intent and enhance the readability of instance creation.
If your convenience initializer hides details, suggests incorrect intent, or otherwise makes your code more confusing, you’re doing it wrong. Good convenience initializers elevate readability by preferring a semantics-driven API over implementation-driven details.
For example, consider a label view type. Its default initializer may rely on laying out a view frame. This is logical from a windowing system’s priorities and meaningless for ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access