public

  • Download Gist
NSString+ConcurrentEnumeration.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#import "NSString+ConcurrentEnumeration.h"
 
@implementation NSString (ConcurrentLineEnumeration)
 
- (void)enumerateConcurrentlyWithOptions:(NSStringEnumerationOptions)options
usingBlock:(void (^)(NSString *substring))block
{
dispatch_group_t group = dispatch_group_create();
[self enumerateSubstringsInRange:NSMakeRange(0, [self length])
options:options
usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclRange, BOOL *stop)
{
dispatch_group_async(group, dispatch_get_global_queue(0, 0), ^ {
block(substring);
});
}];
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
}
 
@end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.