Last active
August 29, 2015 14:03
-
-
Save EvgenyKarkan/9e4f2b2890fe062c5273 to your computer and use it in GitHub Desktop.
Enumerate Objects Using Block
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
- (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; | |
} | |
} | |
} | |
} |
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
I assume you meant
obj
instead ofid
check in theif
statement, but non the less it's not necessary as you won't have nils inside anNSArray
:)