Remove objects using NSPredicate

后端 未结 3 829
盖世英雄少女心
盖世英雄少女心 2021-01-03 15:47

I have the folloving dictionary which has many sub dictionaries. How can I remove objects where isChanged = 1 from parent dictionary using NSPredicate

3条回答
  •  有刺的猬
    2021-01-03 16:33

    when you have array of dictionary than you can remove selected category's data using NSPredicate

    here is code

    NSString *selectedCategory = @"1";
    
    //filter array by category using predicate
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"isChanged == %@", selectedCategory];
    
    NSArray *filteredArray = [yourAry filteredArrayUsingPredicate:predicate];
    
    [yourAry removeObject:[filteredArray objectAtIndex:0]];  
    

    But in your problem data is not in array it is in dictionary

    your data should be in this format

    (
     {
         cellHeight = 437;
         isChanged = 1;
     },
     {
         cellHeight = 145;
         isChanged = 0;
     },
     {
         cellHeight = 114;
         isChanged = 1;
     }
     )
    

提交回复
热议问题