Re: Initialize a subclass object with a base class object
Re: Initialize a subclass object with a base class object
- Subject: Re: Initialize a subclass object with a base class object
- From: Erik Buck <email@hidden>
- Date: Mon, 19 May 2008 15:52:53 -0700 (PDT)
I am not sure I understand the OP's question, but the shortest answer seems to be to override the super class's designated initializer.
http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_6.html
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_13_section_3.html#//apple_ref/doc/uid/TP30001163-CH9-SW8
In the specific case requested, I don't think it is necessary to subclass NSCell or any of its descendants just to store extra data. See -setRepresentedObject: and -representedObject
http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSCell_Class/Reference/NSCell.html#//apple_ref/occ/instm/NSCell/setRepresentedObject:
The represented object can be anything including a dictionary of other objects. Categories can be used to preserve encapsulation when accessing a represented object...
Even if there is a desire to have a represented object as well as arbitrary extra data, the "simulating instance variables" pattern along with a category will solve the problem: http://www.cocoabuilder.com/archive/message/cocoa/2004/12/4/123013
_______________________________________________
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