Re: NSMutableArray subclass (alternatives?)
Re: NSMutableArray subclass (alternatives?)
- Subject: Re: NSMutableArray subclass (alternatives?)
- From: Ben Dougall <email@hidden>
- Date: Mon, 7 Jul 2003 21:54:43 +0100
sub-classing pre-made (that you don't have full accurate details about)
class clusters seems to be a recurring problem i've noticed - just from
reading stuff on here.
you say you over rode all the primatives, but (this is from the book
'cocoa programming') what about over riding all the superclass's
initialiser methods? - or risk exceptions, it says regarding that.
also, every initialiser in the new class must call its superclass's
designated initialiser, which is always -init for abstract interface to
a class cluster.
On Monday, July 7, 2003, at 08:18 pm, Andrew Merenbach wrote:
I've searched the archives and read Apple's docs, but cannot discern
the best answer for my particular situation.
I have an outline view that contains nodes, all of the same class,
that can have children. I have for this purpose subclassed
NSMutableArray to add a title variable, a sorting boolean, a regular
mutable array (not of my subclass) to contain the actual children, and
a weak link to the parent.
I overrode the primitives of NSMutableArray and NSArray, and all
appears well from the logistics side--I can in my program now use all
of the foundation array methods to access the children of any
particular node. The trouble comes when I wish to copy to a
pasteboard; although I have overridden initWithCoder:,
encodeWithCoder:, and classForCoder, I receive the following error
when data is decoded from the pasteboard:
*** initialization method -initWithObjects:count: cannot be sent to
an abstract object of class NPEntry: Create a concrete instance!
The line that causes the error appears to be the call to super's
implementation of initWithCoder:
- (id)initWithCoder:(NSCoder *)decoder {
NSLog(@"decoding %@",decoder);
self = [super initWithCoder:decoder];
.............
1. Is a mutable-array subclass the best idea for this? Although a
composite object could in theory work just as well, I would for
instance not have access to all of the foundation array methods that
could be quite useful in my data management.
(As a second idea, would a category prove better? I could redirect
title: and parent: methods to access, say, the first and/or last
objects, respectively, of an array, thus eliminating the need for a
subclass; although this might prove more convoluted.)
2. From reading the archives, I am under the impression that my error
is the result of sending initWithObjects:count: to the class itself.
Why might the call to NSMutableArray's initWithCoder: cause the error
above?
Take care,
Andrew
_______________________________________________
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.
_______________________________________________
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.