假设我有一个具有以下数据的对象(以 JSON 表示)。我很想知道是否有一种方法可以编写子查询或使用不带块的 NSPredicate 直接提取那些仅具有“W”状态的测试的主题。
即仅从 NSPredicates 获取以下内容。
NSArray *list = [self.event.subjects filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(subject *subject, NSDictionary *bindings) {
for (test *test in subject.tests) {
if ([test.status.lowercaseString isEqualToString:@"w"]) {
return YES;
}
}
return NO;
}]];
{
"id": 860142,
"subjectList": [
{
"id": 12206971,
"testList": [
{
"id": 76904260,
"status": "W"
},
{
"id": 76904291,
"status": "L"
}
]
},{
"id": 12206971,
"testList": [
{
"id": 76904260,
"status": "L"
},
{
"id": 76904291,
"status": "L"
}
]
}
]
}