How do I know which initializer is the designated initializer for ANY class? I'm guessing that it is the one that takes the most parameters, but there could be times where this is not correct.
A designated initializer, or designator, points out a particular element to be initialized. A designator list is a comma-separated list of one or more designators. A designator list followed by an equal sign constitutes a designation.
A designated initializer fully initializes all properties introduced by that class and calls an appropriate superclass initializer to continue the initialization process up to the superclass chain. Convenience initializers are secondary, supporting initializers for a class.
Swift defines two kinds of initializers for class types to help ensure all stored properties receive an initial value. These are known as designated initializers and convenience initializers.
An initializer is a special type of function that is used to create an object of a class or struct. In Swift, we use the init() method to create an initializer.
omz's answer can be stated more firmly: The documentation for a framework class will specify which is the designated initializer. It's necessary to know what the designated initializer is in order to write subclasses that behave properly. The subclass's D.I. must call up to the superclass's D.I. in order to be sure that it is properly initialized.
Your guess about the greatest number of parameters is well-founded, however. Apple actually states that it is often the D.I. in a few places.
Cocoa Core Competencies
The initializer of a class that takes the full complement of initialization parameters is usually the designated initializer.
Cocoa Fundamentals
Some subclasses provide convenience initializers that supply default values to an initializer that takes the full complement of initialization parameters. This initializer is usually the designated initializer, the most important initializer of a class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With