我在xCode中收到此错误消息:
-[__NSCFString substringWithRange:]: Range {18446744073709551615, 1} out of bounds; string length 71. This will become an exception for apps linked after 10.10 and iOS 8. Warning shown once per app execution.
我正试图找到我的代码中发生的事情。
我的项目中有大约十几个substringWithRange方法。我把try catch块放在它们周围:
@try {
substring = [s substringWithRange:NSMakeRange(i, j - i)];
}
@catch (NSException* e) {
NSLog(@"Except: %@", e);
}
没有任何catch块正在执行。
我尝试将部署目标设置为8.4。
任何帮助都会非常感谢!
答案 0 :(得分:4)
大值18446744073709551615是NSNotFound
的值(2 ^ 64-1,可以用64位表示的最大整数)。
您可能首先在另一个字符串中查找(子)字符串,但找不到该子字符串。您可以返回NSNotFound
而不是有效的索引。大概你没有期望或测试这个特殊情况并将NSNotFound
值传递给NSMakeRange()
,从而触发错误。
如果只有少数几个地方可以调用NSMakeRange
,如你所示,那么你应该能够(1)验证这个假设,以及(2)纯粹通过检查代码来修复错误。