gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-30 19:46:49 26 4
gpt4 key购买 nike

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

最佳答案

假设您的第二个字典 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com