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: Tue, 20 May 2008 05:37:03 -0700 (PDT)
1) NSCell is often used along with the Prototype design pattern. See the -setPrototype: method of NSMatrix. When so configured, NSMatrix copies its prototype cell as needed to create new instances.
2) Of course NSCell implements <NSCoding>. Otherwise it couldn't be used in Interface Builder because Interface Builder encodes/archives every object and then decodes/unarchives them (thus deep copying the entire graph of interconnected objects) every time you enter test interface mode. The same thing happens when saving and loading a nib file.
If you implement <NSCoding> in your subclass of NSCell, then the easiest way to deep copy in instance of your cell will be like this:
- (id)deepCopy
{
return [[NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver
archivedDataWithRootObject:self]] retain];
}
Note: the upcoming "Cocoa Design Patterns" book includes information about the Copying, Prototype, and Archiving/Unarchiving patterns. Interestingly, the Prototype pattern examples currently include a MYLabeledBarCell class.
3) It is obviously possible to create a new Interface Builder "plug-in" (formerly pallet) that includes a custom subclass of NSCell or any other AppKit class. The custom objects can then be dragged into interfaces (which involves copying them in some cases) and they will even work in test interface mode.
_______________________________________________
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