Reputation: 599
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
Upvotes: 5
Views: 2857
Reputation: 1303
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
Upvotes: 14
Reputation: 2511
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.
Upvotes: 2