Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple block filter on NSArray in Objective-C
#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];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment