ios - 来自静态分析器的 API 滥用错误

标签 ios static-analysis literals

我从静态分析器中得到这个错误:

这是代码:

API Misuse (Apple) - Dictionary cannot be nil

 - (NSString *)description
{
    return [@{@"filePath": self.filePath,
        @"fileName": self.fileName,
        @"fileAttributes": self.fileAttributes,
        @"creationDate": self.creationDate,
        @"modificationDate": self.modificationDate,
        @"fileSize": @(self.fileSize),
        @"age": @(self.age),
        @"isArchived": @(self.isArchived)} description];
}

谁能告诉我问题出在哪里?

最佳答案

那段代码看起来像是来自 Lumberjack 的 DDFileLogger.m 的旧版本

他们通过在字典中的项目为 nil 时插入默认的空字符串来消除警告 -> https://github.com/CocoaLumberjack/CocoaLumberjack/pull/127/files

    return [@{@"filePath": (self.filePath ?: @""),
          @"fileName": (self.fileName ?: @""),
          @"fileAttributes": (self.fileAttributes ?: @""),
          @"creationDate": (self.creationDate ?: @""),
          @"modificationDate": (self.modificationDate ?: @""),
          @"fileSize": @(self.fileSize),
          @"age": @(self.age),
          @"isArchived": @(self.isArchived)} description];

关于ios - 来自静态分析器的 API 滥用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20453619/

相关文章:

ios - 当按下带有 html 目标 ="_blank"的链接时,用于 navigationAction 函数的 WKWebView 不会从另一个 swift 类调用

android - 如何为 ios 和 android 创建一个可安装在主屏幕上的网络应用程序

php - 如何配置 PHP CodeSniffer 以允许我的 case 语句按照我喜欢的方式缩进?

c - 嵌入式 C 数组索引文字与变量问题

ruby - 为什么在 `/` 之后的正则表达式模式中不允许使用 `#`?

javascript object literal - 嵌套函数和 "this"关键字

ios - FBSDKShareDialogModeNative 在分享点击时调用 sharerDidCancel

ios - 在uitableview中带有空格填充的圆形单元格

cryptography - 您采用哪种安全软件开发实践?

C++ 在 64 位变量中存储 32 位值时发出警告