我通过元素名称作为键在NSMutableDictionary中添加xml数据。如何检查
当我再次添加相同的键而没有循环时,该键在字典中已经可用?
最佳答案
如果您向字典要求使用该键的对象,则如果找不到该对象,它将返回nil。
if([yourDictionary objectForKey:@"yourKey"] == nil){
//Do stuff when yourKey is not in the dictionary yet
}
或者,如果您不在乎以前的值会怎样,我认为您可以使用
[yourDictionary setObject:someObject forKey:someKey]
而不是将对象添加到字典中。
关于iphone - 避免在iPhone SDK的NSMutableDictionary中添加相同的键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7951264/