Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: subclassing NSArrayController



On Mar 3, 2004, at 9:00 AM, Allan Odgaard wrote:
On 3. Mar 2004, at 17:32, Stefan Fisk wrote:
ok, i read a little about it, but i still don't understand what to override, initWithCoder: hardly seems appropriate (although it would work). as i see it, NSArrayController should have a designated initializer that i could piggyback on, but what?
According to the documentation it does not implement a designated initializer,
in fact neither NSArrayController nor its two superclasses (NSObjectController and NSController) implements init:

This is misleading at best. Every class has a designated initialiser. In the absence of other initialisation methods, it is init. Whether or not NSObjectController or NSController implement init is irrelevant to the issue.

-- but NSController implements initWithCoder:.

The relevant issue here is that NSController adopts the NSCoding protocol:
<http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ ObjC_classic/Protocols/NSCoding.html>
that classes must adopt in order to be "archivable" -- a requirement for being part of a NIB file.

Not sure what it is you want to do in the init, but the IB documentation recommends doing 'setup' in awakeFromNib, if you do not like implementing the initWithCoder:.

The significant advantage of using awakeFromNib is that "when an object receives an awakeFromNib message, its guaranteed to have all its outlet instance variables set."
<http://developer.apple.com/documentation/Cocoa/Reference/ ApplicationKit/ObjC_classic/Protocols/NSNibAwaking.html>

If your array controller subclass needs to communicate with other objects in the nib file, then awakeFromNib is the appropriate place to initialise. Otherwise, the method that you use may depend on the class of object you're implementing:
<http://developer.apple.com/documentation/Cocoa/Conceptual/ LoadingResources/Concepts/NibFileLoaded.html>
In the case of non-view classes, and in this case NSController subclasses in particular, initWithCoder: is appropriate.

mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >subclassing NSArrayController (From: Stefan Fisk <email@hidden>)
 >Re: subclassing NSArrayController (From: Allan Odgaard <email@hidden>)
 >Re: subclassing NSArrayController (From: Stefan Fisk <email@hidden>)
 >Re: subclassing NSArrayController (From: Allan Odgaard <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.