-
-
Save anthonyherron/5023637 to your computer and use it in GitHub Desktop.
This file contains 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
@interface NSNumber (Enumeration) | |
- (void)times:(void (^)(NSUInteger index, BOOL *stop))block; | |
@end |
This file contains 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
@implementation NSNumber (Enumeration) | |
- (void)times:(void (^)(NSUInteger index, BOOL *stop))block | |
{ | |
NSInteger count = [self integerValue]; | |
if (count <= 0) | |
return; | |
BOOL stop = NO; | |
for (NSUInteger index = 0; index < count; index++) { | |
block(index, &stop); | |
if (stop) break; | |
} | |
} | |
@end |
Heh. Appreciate the safety check/cleanup of my little throw-away method. Yay open source!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A couple of improvements made here.