Skip to content

Commit

Permalink
added objectForPredicate: method
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Auer committed Aug 9, 2011
1 parent 7f914e4 commit f910528
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CollectionIterators.h
Expand Up @@ -14,6 +14,7 @@
- (NSArray *)reversedArray;
- (BOOL)all:(BOOL (^)(id each))block;
- (BOOL)any:(BOOL (^)(id each))block;
- (id)objectForPredicate:(BOOL (^)(id each))block;
@end

@interface NSDictionary(NSDictionaryIterators)
Expand Down
8 changes: 8 additions & 0 deletions CollectionIterators.m
Expand Up @@ -95,6 +95,14 @@ - (BOOL)all:(BOOL (^)(id))block {
return all;
}

- (id)objectForPredicate:(BOOL (^)(id each))block {
for (id anObject in self) {
if (block(anObject) == YES) {
return anObject;
}
}
}

@end

@implementation NSDictionary(NSDictionaryIterators)
Expand Down

0 comments on commit f910528

Please sign in to comment.