NSPredicate on nested array with NSDictionary as object

回眸只為那壹抹淺笑 提交于 2019-12-02 04:46:46

What you need to do is need enumerate your dictionary and create new filtered Dictionary.

NSMutableDictionary *filterDic = [[NSMutableDictionary alloc] init];
NSPredicate *filter = [NSPredicate predicateWithFormat:@"always_valid = 1"];
[dict enumerateKeysAndObjectsUsingBlock:^(NSString* key, NSArray* obj, BOOL *stop) {
     NSArray *filterArray = [obj filteredArrayUsingPredicate:filter];
     if (filterArray.count > 0) {
         filterDic[key] = filterArray;
     }
}];

Try this :

 NSArray *array = [NSArray arrayWithObject:dict];   // you can also do same for Name key... 
 NSArray *alwaysvalid = [array filteredArrayUsingPredicate:filter];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!