Re: Initialising NSMutableArray
Re: Initialising NSMutableArray
- Subject: Re: Initialising NSMutableArray
- From: "David W. Berry" <email@hidden>
- Date: Mon, 13 Jul 2009 10:51:17 -0500
NSMutableArray (and most/all of the collection classes) is an abstract
class that can't be usefully sub-classed. The object returned by
[NSMutableArray array] is actually a subclass of NSMutableArray. Your
best approach is probably to check out categories which can be used to
add methods to any existing class.
David W. Berry
email@hidden
On Jul 13, 2009, at 10:44 AM, DKJ wrote:
I've subclassed an NSMutableArray, and I want it to be initialised
with some objects already in place. So I did this:
- (id) init
{
self = [super init];
if (self != nil) {
for( int i = 0; i < 3; i++ )
[self addObject:[[[myClass alloc] init] autorelease]];
}
return self;
}
But this produces an NSInvalidArgumentException, with the message:
[NSMutableArray addObject:]: method only defined for abstract
class.
I suspect I'm missing something simple here.
dkj
_______________________________________________
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
_______________________________________________
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