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

我有一个字典数组,其中包含相同的键但不同的值.

我有另一个字典,我想检查这个字典是否存在于该数组中… ??? 最佳答案 假设你的sesond字典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
点赞