替换NSDictionary中的键/值 [英] Replacing key/value in NSDictionary

查看:303
本文介绍了替换NSDictionary中的键/值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个包含以下键/值"foo"/"bar"的字典,并声明为"[dictionary setObject:@"baz" forKey:@"foo"];",是否会将当前键值对替换为"foo"/"baz"并删除"foo"/"bar" ?

If I have a dictionary with the following key/value "foo"/"bar" and declared [dictionary setObject:@"baz" forKey:@"foo"]; would this replace the current key value pair with "foo"/"baz" and delete "foo"/"bar"?

推荐答案

NSMutableDictionary (与任何常见哈希表一样)的行为是,如果不存在,它将创建一个新的键/值对,如果已经存在,则将其替换为新值.

The behave of an NSMutableDictionary (as any common hash table) is that if it does not exists it creates a new key/value pair, if it already exits it will replace the existing value with the new one.

这篇关于替换NSDictionary中的键/值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆