Re: Replacing values in NSDictionary
Re: Replacing values in NSDictionary
- Subject: Re: Replacing values in NSDictionary
- From: James Bucanek <email@hidden>
- Date: Sun, 7 Jan 2007 10:41:27 -0700
Carl Johan Foss wrote on Sunday, January 7, 2007:
>I have an NSMutableArray containing NSDictionary objects in
>"lFullResult", Now I would like to replace a value for the key "id"
>whenever num = st.
>
>How can I do that? the [lFullResult replaceValueAtIndex:0
>inPropertyWithKey:@"id" withValue:vx]; does not seem to work, or I do
>not know how to use it?
Take a deep breath. Let it out. Forget everything you think you know, and start over.
You have an array. Each element of the array is a dictionary. replaceValueAtIndex:inPropertyWithKey: has nothing to do with arrays or dictionaries. It's part of the key-value-complient observer protocol.
Your loop is already iterating through the array, and getting each dictionary in 'item'. I assume that you simply want to change the value for key "id" in 'item' to the value that is in vx.
If the dictionaries in the array are NSMutableDictionaries, then it's easy:
[item setObject:vx forKey:@"id"];
If the dictionaries are immuatable NSDictionary objects, then you'll have to change them into NSMutableDictionary objects before they can be altered.
--
James Bucanek
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden