Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Each class should have one designated initializer. When subclassing, you will typically elect the initializer that contains the most custom parameters, and term it your 'designated'. The important part is that all other initializers (to include, in particular, the default initializer described for the parent classr), call up to this initializer. Only the 'designated' initializer calls super, all others call self.</p> <p>For example:</p> <pre><code>//The default initializer documented by Apple for a given class: - (id)init { self = [super init]; return self; } </code></pre> <p>So, let's say you have several initializers with various options:</p> <p>This custom init has the most parameters, and is your new 'designated'. You'll notice that it calls [super init]:</p> <pre><code>- (id)initWithParamters:(NSObject *)paramterOne andParameter:(NSObject *)paramterTwo { self = [super init]; if (self) { __ivarOne = paramterOne; __ivarTwo = parameterTwo; } return self; } </code></pre> <p>You have an additional custom init, but only takes one parameter. Notice that it calls self (NOT super):</p> <pre><code>- (id)initWithParamter:(NSObject *)parameterOne { return [self initWithParamter:parameterOne andParameter:nil]; } </code></pre> <p>Finally, override the classes default initializer (as specified in documentation):</p> <pre><code>- (id)init { return [self initWithParamter:nil]; } </code></pre> <p>To summarize: You may implement as many custom initializers as you'd like in your subclass. One initializer should be deemed your "designated" initializer, and only this method should implement [super init] (where init is the designated initializer of the super class, which may not be 'init'). All the other initializers should call [self init] (where init is the designated initializer for your subclass).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload