Created
January 18, 2021 02:31
-
-
Save dr2050/a2d347d6935b4cd323664f6967d21b36 to your computer and use it in GitHub Desktop.
Simple block filter on NSArray in Objective-C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "NSArray+Filter.h" | |
@implementation NSArray (Filter) | |
- (NSArray *) filteredArrayUsingBlock:(BOOL (^)(id obj))block { | |
NSIndexSet *const filteredIndexes = [self indexesOfObjectsPassingTest:^BOOL (id _Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) { | |
return block(obj); | |
}]; | |
return [self objectsAtIndexes:filteredIndexes]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment