iphone - 检查字典数组中是否存在字典?

标签 iphone objective-c

我有一个字典数组,其中包含相同的键但不同的值。 我有另一本字典,我想检查该字典是否存在于该数组中……???

最佳答案

假设您的第二个字典 key1、key2、key3 中有三个键,因此要验证您的数组中是否存在该字典,请像这样使用“NSPredicate”类 假设你的数组是 _myDicArray 而其他字典是 _refDic

NSPredicate* myPredicate =[NSPredicate predicateWithFormat:@"key1 like %@ AND key2 like %@ AND key3 like %@",[_refDic objectForKey:@"key1"],[_refDic objectForKey:@"key2"],[_refDic objectForKey:@"key3"]];
NSArray* someOtherArr = [[_myDicArray filteredArrayUsingPredicate:filmPredicate] objectAtIndex:0];
if([someOtherArr count] > 0)
    //this is what you wanted ... this array has ur dic

我觉得这也行

 NSPredicate* myPredicate =[NSPredicate predicateWithFormat:@"self == %@",_refDic];
NSArray* someOtherArr = [[_myDicArray filteredArrayUsingPredicate:filmPredicate] objectAtIndex:0];
if([someOtherArr count] > 0)
    //this is what you wanted ... this array has ur dic

关于iphone - 检查字典数组中是否存在字典?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6690064/

相关文章:

objective-c - AFHTTPRequestOperation 在哪些可能情况下不会调用成功或失败 block ?

ios - 将 'NSError *const __strong *' 发送到类型为 'NSError *__autoreleasing *' 的参数会更改指针的保留/释放属性

iphone - 带有平滑画线的 UIBezierPath onTouch 绘图示例

iphone - 无法解析 SA_OAuthTwitterEngine/MGTwitterEngine 发送的 JSON

iphone - 如何在应用程序退出时清除 SQLite 数据库?

iphone - 除了使用 UIPickerView 之外,如何在 iPhone 编程中显示值列表?

ios - subview 层变换和布局 subview

ios - iOS-AWS Mobile Hub使用开发人员身份验证提供程序登录

ios - 新版本上传后,推送通知在实时应用中不起作用

ios - 来自 URL 的音频流 iOS