Dmitriy Kalachniuk
Dmitriy Kalachniuk

Reputation: 372

How to update key in NSDictionary?

I have an NSArray

I want to make changes to a dictionary stored in the array

My data.plist looks like:

data Array
   Item 0 Dictionary
       imagename String
       name String
       text String
       url String
   Item 1 Dictionary
       imagename String
       name String
       text String
       url String
   Item 2 Dictionary
       imagename String
       name String
       text String
       url String

So I want to update key imagename and name in all items.

How can I do that?

Upvotes: 0

Views: 1293

Answers (1)

Chaosphere2112
Chaosphere2112

Reputation: 674

This should about do it.

-(void)updateKey:(id)newKey oldKey:(id)oldKey atIndex:(int)index {
    [[_myArray objectAtIndex:index] removeObjectForKey:oldKey];
    [[_myArray objectAtIndex:index] setObject:forObject forKey:newKey]; 
}

Upvotes: 1

Related Questions