Reputation: 1354
how would i go about uniquely naming an object and adding it to an nsmutablearray most likely in a for loop?
Upvotes: 1
Views: 102
Reputation: 2672
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.
Upvotes: 1
Reputation: 237070
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.
Upvotes: 3