I am trying with this string to locate first line of every function in my app developed in Objective C: ^-[^{]+{.
This works fine in XCode`s Find>Regular Expression searching.
But when I am trying to use this string in the following function, the function is always returning NULL.
- (void) putLogInFunctionCalls{
NSString *string = @"- (void)setRepresentedObject:(id)representedObject {";
NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^-[^{]+\{" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *modifiedString = [regex stringByReplacingMatchesInString:string options:0 range:NSMakeRange(0, [string length]) withTemplate:[NSString stringWithFormat:@"%@ DLOG()", string]];
NSLog(@"%@", modifiedString);
}
But it should return:
"- (void)setRepresentedObject:(id)representedObject { DLOG()"
This question is specific to detecting a function starting line of Objective-C. Anyone attempting to write meta-codes on iOS/MacOS apps developed in Objective-C might encounter this problem and might find answer usefull. The answer that is marked as duplicate of this one is more generic.
@"^-[^{]+\\{"