What I want to do is to return the NSArray objects of a specific value (numbers). How can I do it?
Thanks in Advance
What I want to do is to return the NSArray objects of a specific value (numbers). How can I do it?
Thanks in Advance
您可以indexesOfObjectsPassingTest:
在您的NSArray
实例上使用。
NSArray *array = @[1, 2, 3];
typedef BOOL (^Predicate)(id obj, NSUInteger idx, BOOL *stop);
Predicate predicate = ^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[NSNumber class]]) {
*stop = YES;
return YES;
} else return NO;
};
NSIndexSet *indexes = [array indexesOfObjectsPassingTest:predicate];