Re: [SOLVED] NSEnumerator confusion
Re: [SOLVED] NSEnumerator confusion
- Subject: Re: [SOLVED] NSEnumerator confusion
- From: Hisaoki Nishida <email@hidden>
- Date: Tue, 20 Sep 2005 16:38:22 -0700
I didn't think of using -allKeys... thanks for that!
I'll report back if I have any problems.
-hyn
On Sep 20, 2005, at 4:26 PM, AgentM wrote:
The documentation is stating that you should do this:
NSEnumerator *e;
id obj;
e=[[dict allKeys] objectEnumerator];
while(obj=[e nextObject])
{
[dict setObject:@"test" forKey:obj];
}
which changes all the values to "test". (Code typed in Mail.app...)
On Sep 20, 2005, at 6:10 PM, Hisaoki Nishida wrote:
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:
40themactionfaction.com
This email sent to email@hidden
|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-
AgentM
email@hidden
|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-
_______________________________________________
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