码迷,mamicode.com
首页 > 其他好文 > 详细

__NSCFString containsString:]: unrecognized selector sent to instance 0x7f876b79e160

时间:2014-12-30 19:07:04      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:ios   __nscfstring   unrecognized selecto   

If you want your code to work on iOS 7 as well as iOS 8 you should use one of the rangeOfString calls instead. 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

原文链接 

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

__NSCFString containsString:]: unrecognized selector sent to instance 0x7f876b79e160

标签:ios   __nscfstring   unrecognized selecto   

原文地址:http://blog.csdn.net/cerastes/article/details/42269389

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!