Skip to content

Instantly share code, notes, and snippets.

@sdsykes
Created November 16, 2010 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdsykes/701632 to your computer and use it in GitHub Desktop.
Save sdsykes/701632 to your computer and use it in GitHub Desktop.
array#detect in obj C
// 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