NSPredicate SUBQUERY for object composed of arrays of other objects
given that I have an object that has the below data (representated in
JSON). I was curious to know if there is a way to write a subquery or use
NSPredicate without blocks to directly extract only those subjects that
have an test with status of "W" only.
ie get the below from just 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"
}
]
}
]
}
No comments:
Post a Comment