您可以使用 过滤数组NSPredicate
,如下所示:
NSArray *data = [NSArray arrayWithObjects:
[NSArray arrayWithObjects:@"One", @"Two", nil]
, [NSArray arrayWithObjects:@"Three", @"Four", nil]
, [NSArray arrayWithObjects:@"Nine", @"Two", nil]
, nil];
NSPredicate *filter = [NSPredicate predicateWithBlock:^BOOL(id array, NSDictionary *bindings) {
// This is the place where the condition is specified.
// You can perform arbitrary testing on your nested arrays
// to determine their eligibility:
return [[array objectAtIndex:1] isEqual:@"Two"];
}];
NSArray *res = [data filteredArrayUsingPredicate:filter];
NSLog(@"%lu", res.count);