I am doing an exercise to learn how to use selectors in Objective-C.
In this code I am trying to compare two strings:
int main (int argc, const char * argv[])
{
@autoreleasepool
{
SEL selector= @selector(caseInsensitiveCompare:);
NSString* str1=@"hello";
NSString* str2=@"hello";
id result=[str1 performSelector: selector withObject: str2];
NSLog(@"%d",[result boolValue]);
}
return 0;
}
But it prints zero.Why?
Edit:
And if I change str2 to @”hell” I get an EXC_BAD_ACCESS.
The documentation for
performSelector:states “For methods that return anything other than an object, use NSInvocation”. SincecaseInsensitiveCompare:returns anNSIntegerinstead of an object you will need to create anNSInvocation, which is more involved.