Skip to content

Instantly share code, notes, and snippets.

@rizumita
Created May 23, 2011 02:09
Show Gist options
  • Save rizumita/986108 to your computer and use it in GitHub Desktop.
Save rizumita/986108 to your computer and use it in GitHub Desktop.
NSString and NSNumber times repeat method like Ruby's times method
@interface NSString (Times)
- (void)times:(void (^)(void))block;
@end
@implementation NSString (Times)
- (void)times:(void (^)(void))block {
for (NSUInteger index = 0; index < [self longLongValue]; index++) {
block();
}
}
@end
@interface NSNumber (Times)
- (void)times:(void (^)(void))block;
@end
@implementation NSNumber (Times)
- (void)times:(void (^)(void))block {
for (NSUInteger index = 0; index < [self longLongValue]; index++) {
block();
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment