NSEnumerator confusion
NSEnumerator confusion
- Subject: NSEnumerator confusion
- From: Hisaoki Nishida <email@hidden>
- Date: Tue, 20 Sep 2005 16:10:06 -0700
Hi,
I have an NSMutableDictionary whose values I want to modify, but
according to the docs I am not allowed to do this *while*
enumerating, and instead need to work with a snapshot of the dictionary:
"When this method is used with mutable subclasses of NSDictionary,
your code shouldn’t modify the entries during enumeration. If you
intend to modify the entries, use the allValues method to create a
“snapshot” of the dictionary’s values. Work from this snapshot to
modify the values."
What does this mean? Does it mean that I need to modify the snapshot
after the enumeration loop? The -allValues method returns an NSArray
of values in the dictionary, but I also need access to the keys
because I determine which object to modify based on a key. The order
isn't even defined, so how am I supposed to work with it?
In code, this is what I would do, if such a thing was allowed:
NSEnumerator *enumerator = [myDictionary objectEnumerator];
id value;
while ((value = [enumerator nextObject]))
{
// ***this is not allowed during enumeration according to docs?
[value removeObjectForKey: @"myNumber"];
[value setObject: [NSNumber numberWithInt: someInt] forKey:
@"myNumber"];
}
Thanks,
-hyn _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden