开发者

Updating NSMutableArray of dictionary objects

I have a NSMutableArray (i.e. "stories") of dictionary items.

I can read the dictionary items in the array just fine, e.g.

[[[stories objectAtIndex: b] objectForKey: @"title"] 

But, now I am trying to update (i.e. replace) a couple of objects e.g. "title" & "matchingword", but I cannot find the right code. Any suggestions are much appreciated.

I tried this, but it seems to be adding entirely new objects to the array

NSMutableDictionary *itemAtIndex = [[NSMutableDictionary alloc]init];
[itemAtIndex setObject:[[placesArray objectAtIndex:a]objectAtIndex:0] forKey:@"reference"];
[stories replaceObjectAtIndex:x withObject开发者_开发百科:itemAtIndex];  // replace "reference" with user's unique key
[itemAtIndex release];

I also tried this (but didn't work either):

//NSMutableDictionary *itemAtIndex2 = [[NSMutableDictionary alloc]init];
//[itemAtIndex2 setObject:[separatePlaces objectAtIndex:x] forKey:@"matchingword"];
//[stories insertObject:itemAtIndex2 atIndex:x];  // add the unique matching word to story
//[itemAtIndex2 release];

Help appreciated. Thanks.


You need to grab the dictionary you want to mod.

NSMutableDictionary *temp = [stories objectAtIndex: b];

The change the value:

[temp setObject:@"new Info" forKey:@"title"];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜