Created
November 16, 2010 09:43
-
-
Save sdsykes/701632 to your computer and use it in GitHub Desktop.
array#detect in obj 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
// block test - same as using ruby's Array#detect, but much more long winded | |
- (BOOL (^)(id obj, NSUInteger idx, BOOL *stop))inbro_test:(NSUInteger)inbro_id { | |
return [[^(id obj, NSUInteger idx, BOOL *stop) { | |
if ([obj inbro_id] == inbro_id) { | |
*stop = YES; | |
return YES; | |
} | |
return NO; | |
} copy] autorelease]; | |
} | |
NSUInteger idx = [items indexOfObjectPassingTest:[self inbro_test:[item intValue]]]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment