NSPredicate on nested array with NSDictionary as object

前端 未结 2 943
故里飘歌
故里飘歌 2021-01-23 16:47

i have a NSDictionary like:

{
\"2017-05-02\" =     (
            {
        \"always_valid\" = 0;
        date = \"2017-05-02\";
        from = \"12:00\";
                


        
2条回答
  •  别那么骄傲
    2021-01-23 17:19

    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;
         }
    }];
    

提交回复
热议问题