_ NSCFString containsString:]: unrecognized selector sent to instance 0x7f876b79e160, nscfstring

Source: Internet
Author: User

_ NSCFString containsString:]: unrecognized selector sent to instance 0x7f876b79e160, nscfstring

If you want your code to work on iOS 7 as well as iOS 8 you shoshould use one of the rangeOfString callinstead. basically if the range returned has a length of zero, the substring is not there.

/* These methods return length==0 if the target string is not found. So, to check for containment: ([str rangeOfString:@"target"].length > 0).  Note that the length of the range returned by these methods might be different than the length of the target string, due composed characters and such.*/- (NSRange)rangeOfString:(NSString *)aString;- (NSRange)rangeOfString:(NSString *)aString options:(NSStringCompareOptions)mask;- (NSRange)rangeOfString:(NSString *)aString options:(NSStringCompareOptions)mask range:(NSRange)searchRange;- (NSRange)rangeOfString:(NSString *)aString options:(NSStringCompareOptions)mask range:(NSRange)searchRange locale:(NSLocale 


@implementation NSString (Contains)- (BOOL)myContainsString:(NSString*)other {  NSRange range = [self rangeOfString:other];  return range.length != 0;}@end

Original article link

Http://stackoverflow.com/questions/26410420/nsstring-containsstring-crashes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.