5

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

Esha
  • 1,328
  • 13
  • 34
Tarun Sharma
  • 601
  • 3
  • 13
  • 31

2 Answers2

14

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

Esha
  • 1,328
  • 13
  • 34
2

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.

Jayeshkumar Sojitra
  • 2,501
  • 4
  • 31
  • 44
  • 1
    `NSString *strn = @"my vals"; if ([strn containsString:@"va"]) { NSLog(@"GOT IT RE..."); }` This thing works in ios8 but throws exception in iOS7. – Esha Dec 02 '14 at 05:46
  • 1
    I think this function is added in ios8 & does not work in ios7 that is why it is throwing an exception. i have checked on both ios8 & ios7 – Tarun Sharma Dec 02 '14 at 05:52