NSPredicate for inner key in array of dictonary

后端 未结 3 1033
温柔的废话
温柔的废话 2021-01-24 20:35

i have an array of dictionay in the following format

    [
 {
      \"student\": {
        \"id\": \"1\",

        \"studentUserDetail\": {
          \"firstName         


        
3条回答
  •  清酒与你
    2021-01-24 21:14

    NSString *name = @"Bonny";
    NSPredicate *pred = [NSPredicate predicateWithFormat:
                        @"student.studentUserDetail.firstName == %@", name];     
    NSArray *arr = [self.anArray filteredArrayUsingPredicate:pred];
    
    NSLog(@"Bonny found at : %@", arr);
    

    Edit:

    If you want to search based on a pattern, then use:

    NSPredicate *pred = [NSPredicate predicateWithFormat:
                        @"student.studentUserDetail.firstName beginswith[cd] %@", name];
    

提交回复
热议问题