Skip to content

Instantly share code, notes, and snippets.

@anthonyherron
Forked from bencochran/NSNumber+Enumeration.h
Last active December 14, 2015 03:49
Show Gist options
  • Save anthonyherron/5023637 to your computer and use it in GitHub Desktop.
Save anthonyherron/5023637 to your computer and use it in GitHub Desktop.
@interface NSNumber (Enumeration)
- (void)times:(void (^)(NSUInteger index, BOOL *stop))block;
@end
@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
@bencochran
Copy link

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