Unrecognized selector sent to instance exception in iOS7

I have a requirement to check if a string contains a specific string or not. For this purpose, I use an NSString class function with containsstring . This function works fine in ios8 without any exception, but in the case of ios7 it throws an exception called

unrecognized selector sent to instance 

I used a try and catch block to prevent an exception, but can I know why this is happening?

Thanks in advance

+5
source share
2 answers

You can check the title of the framework. enter image description here

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

This containsString method exists only after iOS 8, so it is obvious that it will cause an error in iOS7 ....

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

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

Perhaps this may solve your problem. Thanks

+14
source

Check if String is found from nil array. This will solve your problem.

Use the following code that may solve your problem.

 NSString *Test=arr_sub[0]; if(Test!=nil && [Test containsString:@"::"]) { NSlog(@"charecter found"); } 

Let me know if you run into any other outcome.

+2
source

Source: https://habr.com/ru/post/1208100/


All Articles