替换iPhone中的NSDictionary中的值 [英] Replace a value in NSDictionary in iPhone
本文介绍了替换iPhone中的NSDictionary中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个NSDictionaryitem的数组(dataArray)。对于5名学生,它具有关键名称的david和关键标记等的85等数据。我想将david的标记替换为数组索引值的90(即0表示包含david和85的字典)。我该怎么办?
I have a array (dataArray) of NSDictionary "item". It has datas like "david" for key "name" and "85" for key "marks" etc for 5 students. I want to replace the mark of david to 90 with respect to the array index value (ie 0 for dictionary containing david and 85). How can I do it?
数组中内容的代码是
[item setobject:name forkey:@"Name"];
[item setobject:mark forkey:@"Marks"];
[dataArray addOject:item]
上面的代码进入解析,所以我有数组有5个对象(学生),他们的名字和标记,现在我想替换dataArray中第一个对象的标记。
The above code goes inside parsing, so i have array with 5 objects (students), their name and marks, now I want to replace the mark of the first object in the dataArray.
推荐答案
这是你可以做的:
NSMutableDictionary *newDict = [[NSMutableDictionary alloc] init];
NSDictionary *oldDict = (NSDictionary *)[dataArray objectAtIndex:0];
[newDict addEntriesFromDictionary:oldDict];
[newDict setObject:@"Don" forKey:@"Name"];
[dataArray replaceObjectAtIndex:0 withObject:newDict];
[newDict release];
希望这有帮助!
这篇关于替换iPhone中的NSDictionary中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文