如何查找NSMutableDictionary中是否存在给定字符串

时间:2014-11-05 10:12:17

标签: ios objective-c xcode nsmutabledictionary

我有NSString =@"KEY3";NSMutableDictionary *AllValues ;,如下所示。我只需要检查字符串是否是AllValues Dictionary

的元素之一
KEY1 {
    MLCAvailable = "test";
    MLCColorCode = "test2";
     NotesCount = "test3";
     },
KEY2 {
    MLCAvailable = "test";
    MLCColorCode = "test2";
     NotesCount = "test3";
     },
KEY3 {
    MLCAvailable = "test";
    MLCColorCode = "test2";
     NotesCount = "test3";
     },
KEY4 {
    MLCAvailable = "test";
    MLCColorCode = "test2";
     NotesCount = "test3";
     },

How should i find whether they KEY 3 is present in the given MutableDictionary ?

2 个答案:

答案 0 :(得分:4)

你可以尝试获取元素......

if(AllValues[@"KEY3"]) {
   //The element exists
}

答案 1 :(得分:1)

你可以在for loop

的帮助下找到它
 for (NSString *strKey in [AllValues allKeys]) {

            if ([strKey isEqualToString:@"KEY3"]) {
                //your condition
            }
        }

有用吗?