ObjC在字符串中搜索@(iOS @转义码)

时间:2013-09-19 19:22:31

标签: ios objective-c nsstring

我正在使用电子邮件搜索NSString以查找@字符。这是代码:

NSRange range = [string rangeOfString:@"@"];
if (range.location != NSNotFound) // do stuff

这是我得到的错误......

-[__NSCFNumber rangeOfString:]: unrecognized selector sent to instance 0x1e51c550
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber rangeOfString:]: unrecognized selector sent to instance 0x1e51c550'

1 个答案:

答案 0 :(得分:4)

您的string变量指向NSNumber的实例,而不是NSString的实例。您正在初始化它。