【发布时间】:2014-10-14 10:44:12
【问题描述】:
不能在 64 位应用程序中使用 int。现在尝试使用long。但它在 NSMakeRange 中不起作用
long i;
for (long i = 0;i<4;i++){
NSLog(@"range:--- %ld",i);
range.location= i; //possibly crash here
subStr =[str substringWithRange:range];
}
错误信息:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFString substringWithRange:]: Range {1, 1} out of bounds; string length 1'
【问题讨论】:
-
你能发布错误信息吗?范围或索引是否超出范围?试试这个stackoverflow.com/questions/11131472/…
-
*** 由于未捕获的异常 'NSRangeException' 导致应用程序终止,原因:'-[__NSCFString substringWithRange:]: Range {1, 1} out of bounds;字符串长度 1'
-
使用 NSInteger 而不是 long 来正确支持 64 位。您的崩溃是由于尝试对小于您指定范围的字符串进行子串化造成的。