Reputation: 684
i'm trying to replace a value in my NSDictionnary but i cannot reach the part i'm looking for
I would like to use this method, or kind of...
i have a NSDictionnary and i want to replace this :
[[rootObj objectAtIndex:0] valueForKey:@"check"]
there is this method :
rootObj replaceObjectAtIndex:<#(NSUInteger)#> withObject:<#(id)#>
but i cannot acces to the valueForKey... how can i reach it ?
Thanks !
Upvotes: 0
Views: 145
Reputation: 12780
use this code for replace code
EDIT: Update answer according to user's match
NSMutableDictionary *newDict = [[NSMutableDictionary alloc] init];
NSDictionary *oldDict = (NSDictionary *)[rootObj objectAtIndex:0];
[newDict addEntriesFromDictionary:oldDict];
[newDict setObject:@"1" forKey:@"check"];
[rootObj replaceObjectAtIndex:0 withObject:newDict];
In the above example i want to replace the object of @"Sales Qty" so i have create dictionary and set the object in those dictionary then just set the value for @"Sales Qty" key and replace the whole dictionary in array
If you have still problem then let me know
Upvotes: 0
Reputation: 38259
Firstly get all keys like this:
NSArray *arrKeys = [yourDictionary allKeys];
Now replace like this say u want replace second object :
if([arrKeys objectAtIndex:1]) //key for second Object
{
[yourDictionary setObject:yourNewValueHere forKey:[arrKeys objectAtIndex:1]]; //it overwrites value
}
Upvotes: 1