如何将 NSPredicate 与多维数组一起使用(其中 predicateFormat 存在于 valueForKeyPath 中)

How to use NSPredicate with Multidimensional array (where the predicateFormat exists at valueForKeyPath)

我有一个数组,其中我要过滤数组的 'id' 存在于每个字典的 valueForKeyPath 'objectId' 中。如何比较 ValueForKeyPath.

中的谓词

目前..这个谓词

NSPredicate * objIdPredicate = [NSPredicate predicateWithFormat:@"objectId = %@",obj];
NSArray * oneOrder = [array filteredArrayUsingPredicate:objIdPredicate];

正在考虑数组元素的键和值,而不是 ValueForKeyPath=@"objectId"

处的键和值

在您的代码中使用 "self" 获取数组元素的 valueForKeyPath

NSPredicate *objIdPredicate =[NSPredicate predicateWithFormat:@"(self.objectId = %@)",obj];

`