Created
January 4, 2012 00:17
-
-
Save jparise/1557727 to your computer and use it in GitHub Desktop.
NSArray Predicates
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 <Foundation/NSArray.h> | |
@interface NSArray (Predicates) | |
- (NSArray *)arrayOfObjectsPassingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate; | |
- (NSArray *)arrayOfObjectsWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate; | |
@end |
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
@implementation NSArray (Predicates) | |
- (NSArray *)arrayOfObjectsPassingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate | |
{ | |
NSIndexSet *indexes = [self indexesOfObjectsPassingTest:predicate]; | |
return [self objectsAtIndexes:indexes]; | |
} | |
- (NSArray *)arrayOfObjectsWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate | |
{ | |
NSIndexSet *indexes = [self indexesOfObjectsWithOptions:opts passingTest:predicate]; | |
return [self objectsAtIndexes:indexes]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment