Skip to content

Instantly share code, notes, and snippets.

@akfreas
Created March 25, 2014 21:05
Show Gist options
  • Save akfreas/9771363 to your computer and use it in GitHub Desktop.
Save akfreas/9771363 to your computer and use it in GitHub Desktop.
How to create block factories in Objective-C
BOOL(^(^comparator)(NSString *, NSString *, BOOL))(NSString *, NSDictionary *) = ^BOOL(^(NSString *prefixString, NSString *typeString, BOOL hasNumberedSuffix))(NSString *, NSDictionary *) {
return ^BOOL(NSString *str, NSDictionary *dict) {
NSString *regexString = [NSString stringWithFormat:@"%@_([0-9]{2})_%@", prefixString, typeString];
NSError *err = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexString options:nil error:&err];
if ([[regex matchesInString:str options:0 range:NSMakeRange(0, [str length])] count] > 0) {
return YES;
} else {
return NO;
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment