__NSCFString containsString:]: unrecognized selector sent to instance 0x7f876b79e160
2014-12-30 17:59
393 查看
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
/* 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 0x17d68490
- __NSCFString containsString:]: unrecognized selector sent to instance 的解决方案
- __NSCFString containsString:]: unrecognized selector sent to instance 的解决方案
- 问题人生[20160330] -[NSCFString containsString:]: unrecognized selector sent to instance 0x7f9902724da0
- [__NSCFString containsString:]: unrecognized selector sent to instance 的解决方案
- -[__NSCFString longValue]: unrecognized selector sent to instance
- [__NSCFString ma_MD5String]: unrecognized selector sent to instance 0x7ffeb34aaa80'
- swift有关setValue崩溃,报告错误为NSCFString longValue unrecognized selector sent to instance
- [__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x17deba00
- 关于使用JSON库的时候,出现[NSCFString JSONValue]: unrecognized selector sent to instance的问题
- 关于使用JSON库的时候,出现[NSCFString JSONValue]: unrecognized selector sent to instance的问题
- 错误:[__NSCFString md5Hash]: unrecognized selector sent to instance 0x223120'
- xcode 运行出现类似-[__NSCFString objectForKey:]: unrecognized selector sent to instance的调试方法
- uitableview 滑动时 报错-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance
- xcode 运行出现类似-[__NSCFString objectForKey:]: unrecognized selector sent to instance的调试方法
- 关于使用JSON库的时候,出现[NSCFString JSONValue]: unrecognized selector sent to instance的问题
- 奔溃警告:-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x7a781910
- -[__NSCFString objectFromJSONString]: unrecognized selector sent to 解决办法
- ios6 NSMutableAttributedString -[__NSCFType set]: unrecognized selector sent to instance 0xbbf3600
- [NSConcreteMutableData wbsdk_base64EncodedString]: unrecognized selector sent to instance