I took some examples how to use RegularExpression in Objective-c. The problem is I want to use the same code for Linux (gnustep) and for OSX too. After small changes it works in OSX but not under Linux.
NSArray* matches = [regex matchesInString:line options:0
range: NSMakeRange(0,[line length])];
if ([matches count] > 0) {
for (NSTextCheckingResult* match in matches) {
NSString* matchText = [line substringWithRange:[match range]];
NSLog(@"match: %@", matchText);
NSRange group1 = [match rangeAtIndex:1];
NSLog(@"group1: %@", [line substringWithRange:group1]);
}
}else{
NSLog(@"nomatch %@",[matches count]);
}
When I want to compile this part of code compilator will return errors:
error:
sending 'id' to parameter of incompatible type 'NSRange' (aka 'struct _NSRange')
NSString* matchText = [line substringWithRange:[match range]];
initializing 'NSRange' (aka 'struct _NSRange') with an expression of
incompatible type 'id'
NSRange group1 = [match rangeAtIndex:1];
I don't understand why :-(
property range
and rangeAtIndex
should by returned by NSTextCheckingResult
as NSRange
and not id
.
Is there a way how to covert id to NSRange please?
Thank you