objective-c 如何更新 NSMutableDictionary?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2227400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to update NSMutableDictionary?
提问by S.P.
I have an NSMutableDictionary.
我有一个 NSMutableDictionary。
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
I have to update an element in that dictionary. How i can do that?
我必须更新该字典中的一个元素。我怎么能这样做?
回答by Mihir Mathuria
回答by pedrotorres
dictionary only allows you to have one objects for each key so if you use "set object for key" it will update the current one
字典只允许您为每个键拥有一个对象,因此如果您使用“为键设置对象”,它将更新当前的对象
回答by Renetik
NSMutableDictionary's method addEntriesFromDictionary.
NSMutableDictionary 的方法addEntriesFromDictionary。
If both dictionaries contain the same key, the receiving dictionary's previous value object for that key is sent a release message, and the new value object takes its place.
如果两个字典都包含相同的键,则接收字典的该键的先前值对象将被发送一个释放消息,并且新值对象取代它。

