【问题标题】:How to Find whether the given string is present in the NSMutableDictionary如何查找给定的字符串是否存在于 NSMutableDictionary 中
【发布时间】:2014-11-05 10:12:16
【问题描述】:

我有一个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 ?

【问题讨论】:

  • if ([AllValues objectForKey:@"KEY3"]) { NSLog(@"YES"); }

标签: ios objective-c xcode nsmutabledictionary


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    你可以在for循环的帮助下找到它

     for (NSString *strKey in [AllValues allKeys]) {
    
                if ([strKey isEqualToString:@"KEY3"]) {
                    //your condition
                }
            }
    

    有用吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-28
      • 2022-06-29
      • 1970-01-01
      • 1970-01-01
      • 2012-05-01
      相关资源
      最近更新 更多