NSPredicate on nested array with NSDictionary as object

前端 未结 2 944
故里飘歌
故里飘歌 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 16:55

    Try this :

     NSArray *array = [NSArray arrayWithObject:dict];   // you can also do same for Name key... 
     NSArray *alwaysvalid = [array filteredArrayUsingPredicate:filter];
    
    0 讨论(0)
  • 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;
         }
    }];
    
    0 讨论(0)
提交回复
热议问题