Created
March 25, 2014 21:05
-
-
Save akfreas/9771363 to your computer and use it in GitHub Desktop.
How to create block factories in Objective-C
This file contains hidden or 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
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