Re: arrayWithObjects question
Re: arrayWithObjects question
- Subject: Re: arrayWithObjects question
- From: Brent Gulanowski <email@hidden>
- Date: Wed, 24 Jul 2002 00:39:24 -0400
On Tuesday, July 23, 2002, at 07:42 PM, Hisaoki Nishida wrote:
Hi,
I have a newbie question with arrays.
I want to add to an NSArray a number of objects of the same type.
The contents don't have to be removed/added, but I need to modify some
instance variables in the objects in the array. I could just do:
myArray = [NSArray arrayWithObjects: [MyObject object],
[MyObject object],
[MyObject object],
..., // X number of MyObject objects
nil];
But I need a lot of my MyObject objects, and doing this manually would
take lots of space.
What do I use in this case? I couldn't find any method that does this in
NSArray reference doc.
There is another method for NSArray, -arrayWithObjects:count: which lets
you add the objects from a standard C pointer array. I'd say that way or
the loop suggestion would be right, depending on the situation -- as in,
how are you initially instantiating all of these objects?
If you are doing this a lot and want to avoid many many messages, just
declare an array of id and put the objects in there temporarily and then
move them into the NSArray. If it's an infrequent thing, just use the loop.
brent
--
Inkubator: creating free, open source Mac games.
http://inkubator.idevgames.com - homepage
http://www.sourceforge.net/project/inkubator - project page
http://64.246.17.165/forum/forumdisplay.php?s=&forumid=17 - discussion
forums
_______________________________________________
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.