Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, you don't have constructors, you have two initializers:</p> <pre><code>- (id)initWithTitle:(NSString *)title; - (id)initWithTitle:(NSString *)title page:(NSString *)page; </code></pre> <p>As with most initializers, the goal is to setup some instance variables (not member variables).</p> <p>The first step is to identify your designated initializer. In your case, it could be:</p> <pre><code>- (id)initWithTitle:(NSString *)title page:(NSString *)page; </code></pre> <p>Which means that <code>- (id)initWithTitle:(NSString *)title;</code> would be implemented as others have described:</p> <pre><code>- (id)initWithTitle:(NSString *)_title { return [self initWithTitle:_title page:nil]; } </code></pre> <p>However, I would recommend against this pattern as it makes subclassing more error prone than it should be. In subclassing, you must always override the designated initializer <em>or</em> you must implement a new initializer that calls the designated initializer. Obviously, the more initializers you have, the more potential for bugs in subclassing you might introduce.</p> <p>Furthermore, this:</p> <pre><code>Foo *f = [[Foo alloc] initWithTitle: @"Foo!" page: nil]; </code></pre> <p>Is far more clear than this:</p> <pre><code>Foo *f = [[Foo alloc] initWithTitle: @"Foo!"]; </code></pre> <p>The first indicates quite specifically that you have thought about <code>page</code> and decided to explicitly set it to <code>nil</code> or otherwise rely on the class <code>Foo</code> to set the page reasonably. The second gives no such indication.</p> <p>Both subclassing and explicit indication of intention are the primary reasons why you will find a lack of such convenience methods across Cocoa (there are some, but most are quite old -- older than when the policy really became rule).</p>
    singulars
    1. This table or related slice is empty.
    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. 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