• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSWindowController and designated initializer rules
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSWindowController and designated initializer rules


  • Subject: Re: NSWindowController and designated initializer rules
  • From: Bavarious <email@hidden>
  • Date: Mon, 23 Jun 2014 14:59:10 -0300

On 23 Jun 2014, at 14:38, Sean McBride <email@hidden> wrote:
> Hi all,
>
> The Obj-C designated initializer rules say that if a subclass creates a new designated initializer that its implementation must call (one of) the superclass' designated initializer.
>
> The docs for NSWindowController say initWithWindow: is the (only) designated initializer.
>
> Countless examples of NSWindowController subclassing, like Apple's Sketch sample code:
>
> <https://developer.apple.com/library/mac/samplecode/Sketch/Listings/SKTWindowController_m.html>
>
> do this:
>
> - (id)init {
>    // Do the regular Cocoa thing, specifying a particular nib.
>    self = [super initWithWindowNibName:@"DrawWindow"];
> }
>
> So there seems to be a contradiction here... Are the docs just omitting that initWithWindowNibName: is in fact a secondary designated initializer?

If Sketch were strictly following these rules, -init would contain [self initWith…] instead of super because -init is a convenience initialiser of SKTWindowController. Since often times direct NSWindowController subclasses are final in practice (no further subclasses) and window controller initialisation happens after the nib file has been loaded, notably in -windowDidLoad, it’s common for initialisers to be almost empty, so skipping self and sending -initWithWindowNibName: to super doesn’t hurt.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >NSWindowController and designated initializer rules (From: Sean McBride <email@hidden>)

  • Prev by Date: NSWindowController and designated initializer rules
  • Next by Date: Animating UICollectionViewCell selection
  • Previous by thread: NSWindowController and designated initializer rules
  • Next by thread: Re: NSWindowController and designated initializer rules
  • Index(es):
    • Date
    • Thread