Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unrecognized selector sent to instance exception in iOS7

I have a requirement to check whether a String contains a particular string or not.For that purpose i am using a function of NSString class called ccontainsstring. This function works fine in ios8 without throwing any kind of exception but in case of ios7 it is throwing an exception called

 unrecognized selector sent to instance 

I have used try & catch block to prevent the exception but may i know why this is happening?

Thanks in advance

like image 205
Tarun Sharma Avatar asked Dec 02 '14 05:12

Tarun Sharma


People also ask

What does unrecognized selector sent to instance mean?

Once you run this line of code you will instantly get an error message in the console area, which look s like this (unrecognized selector sent to instance). Since the selector is another name for the method, the error is basically saying that it doesn't recognize the function that you're trying to call on this object.


1 Answers

You can check in framework header. enter image description here

- (BOOL)containsString:(NSString *)aString NS_AVAILABLE(10_10, 8_0);

This method of containsString only exist after iOS 8 so its obvious that it will throw error in iOS7....

Please use below method for ios7 and you can use above method for ios8:

if ([string rangeOfString:@"bla"].location != NSNotFound)
{
  NSLog(@"charecter found");
} 

May be this can solve your issue. Thanks

like image 140
Esha Avatar answered Sep 21 '22 05:09

Esha