在构建时,我没有收到任何警告,但在归档时,我收到了很多键入警告,所有这些警告都涉及 stringWithFormat,还有一个是使用 NSNotFound 的问题。我能够解决除一个之外的所有 stringWithFormat 问题,但仍然被 NSNotFound 问题难住了。下面列出了这些。谢谢你的帮助
下面的代码...
if ([[NSString stringWithFormat:@"%.*s", [data length], [data bytes]] isEqualToString:@"Success"]) {
return YES;
}
为格式字符串生成此警告...
Field precision should have type 'int', but argument has type 'NSUInteger' (aka 'unsigned long')
下面的代码...
if (![_response rangeOfString:@"|TreatmentCards|0|"].location == NSNotFound) {
return NO;
}
产生...
Comparison of constant 'NSNotFound' (9223372036854775807) with expression of type 'int' is always false
最佳答案
我在抓取可变数组的索引时遇到了这个问题。此 link有助于理解问题。问题的根源在于返回的数据类型永远不会命中 NSNotFound
.相反,将其设置为:
NSUInteger location = [_response rangeOfString:@"|TreatmentCards|0|"].location;
if (location != NSNotFound) {
return NO;
}
可能有更清洁的方法,但这应该有效。如果将长度声明为数据类型
int
的变量,它也可以用于上述问题。 .
关于xcode - 归档时 Xcode 中的几个打字问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23961911/