xcode - 归档时 Xcode 中的几个打字问题

标签 xcode type-conversion

在构建时,我没有收到任何警告,但在归档时,我收到了很多键入警告,所有这些警告都涉及 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/

相关文章:

ios - 在 ScrollView 中放置 View 和元素

swift - Pod lib lint 失败 - 自动链接提供...文件是为 x86_64 构建的,这不是正在链接的架构(i386)

C++ int 限制的提升动机

java - 如何在 java 中将 Long 转换为 byte[] 并返回

python-3.x - 将 24 位音频转换为 16 位音频的最佳库或方法是什么?

ios - UIWebView 弹跳回调

ios - 不使用 Xcode 制作 Cocoa 应用程序,例如 : using VIM for editing and the Swift compiler

swift - 将 Firebase 导入 Xcode 项目时出现问题

c++ - MPI_Op_create : candidate function not viable. 自定义结构指针不能解释为空指针

javascript - 在 Java 和 MySQL 中使用日期格式