• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Initialising NSMutableArray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Initialising NSMutableArray (From: DKJ <email@hidden>)

  • Prev by Date: Re: [iPhone] Network connection between 2 iPhones
  • Next by Date: Re: [iPhone] Network connection between 2 iPhones
  • Previous by thread: Re: Initialising NSMutableArray
  • Next by thread: [iPhone] Network connection between 2 iPhones
  • Index(es):
    • Date
    • Thread