Skip to content

Instantly share code, notes, and snippets.

@EvgenyKarkan
Last active August 29, 2015 14:03
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 EvgenyKarkan/9e4f2b2890fe062c5273 to your computer and use it in GitHub Desktop.
Save EvgenyKarkan/9e4f2b2890fe062c5273 to your computer and use it in GitHub Desktop.
Enumerate Objects Using Block
- (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block {
NSParameterAssert(block != NULL);
NSUInteger idx = 0;
for(id obj in self) {
BOOL stop = NO;
block(obj, idx++, &stop);
if(stop) {
break;
}
}
}
}
@Ciechan
Copy link

Ciechan commented Jul 2, 2014

I assume you meant obj instead of id check in the if statement, but non the less it's not necessary as you won't have nils inside an NSArray :)

@EvgenyKarkan
Copy link
Author

oh shit, of course, damn insomnia =)
I must say, I am pedantic sometimes to check potentially risky things. But pre-optimization often is a evil ;)
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment