我有一个字典数组,其中包含相同的键但不同的值。 我有另一本字典,我想检查该字典是否存在于该数组中……???
最佳答案
假设您的第二个字典 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/