简体   繁体   中英

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 c containsstring . 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

You can check in framework header. 在此输入图像描述

- (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

Check if String retrieved from array is not nil . It will solve your problem.

Use following code it might resolve your issue.

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

Let me know if you face any other isssue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM