how would i go about uniquely naming an object and adding it to an nsmutablearray most likely in a for loop?
+3
A:
You're confusing objects and variables. Variables have names; objects don't unless you give them some name
instance variable. More to the point, the same variable can reference different objects at different times. Given some collection of objects collection
:
NSMutableArray *array = [NSMutableArray array];
for (id item in collection) {
[array addObject:item];
}
This will create a mutable array with all the objects in collection
, with the item
variable pointing to a different object from collection
on each iteration of the loop.
Chuck
2010-09-01 21:09:20
+1
A:
If you want to uniquely name instances then instead of an array how about using a NSDictionary? Then you can grab the array of keys from it. Run through this key array to get the name of a particular instance and then use that key to get the actual object instance from the dictionary.
No one in particular
2010-09-02 00:11:10
thats a good idea, but unfortunately i don't believe i can do what i want which is to create an array (or NSDictionary in this case) and then create outlets for each instance and @synthesize them so they can be acted upon elsewhere, if that makes any sense
Joe
2010-09-02 13:18:05