NSPredicate为dictonary数组中的内键

Has*_* MH 1 arrays objective-c nspredicate ios

我有以下格式的一系列词典

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

        "studentUserDetail": {
          "firstName": "Bonny",
          "lastName": "Roby"  
        }
    }

 },

 {
      "student": {
        "id": "1",

        "studentUserDetail": {
          "firstName": "Bonny",
          "lastName": "Kety"  
        }
    }

 },

 {
      "student": {
        "id": "1",

        "studentUserDetail": {
          "firstName": "Arther",
          "lastName": "Fone"  
        }
    }

 },

]
Run Code Online (Sandbox Code Playgroud)

在上面的数组中,我需要在内部键student.StudentUserDetails.firstName中过滤包含serachKey(例如Bonny)的所有元素.我如何使用NSPredicate进行过滤

Ano*_*dya 5

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

NSLog(@"Bonny found at : %@", arr);
Run Code Online (Sandbox Code Playgroud)

编辑:

如果要基于模式进行搜索,请使用:

NSPredicate *pred = [NSPredicate predicateWithFormat:
                    @"student.studentUserDetail.firstName beginswith[cd] %@", name];
Run Code Online (Sandbox Code Playgroud)