使用filterUsingPredicate:这将根据数组内容评估给定谓词,并返回匹配的对象。
例:
NSMutableArray *array = [NSMutableArray array]; [array setArray:@[@"iOS",@"macOS",@"tvOS"]]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] 'i'"]; NSArray *resultArray = [array filteredArrayUsingPredicate:predicate]; NSLog(@"%@",resultArray);