【问题标题】:'fileExists' produces 'Bool', not the expected contextual result type 'Bool'“fileExists”产生“Bool”,而不是预期的上下文结果类型“Bool”
【发布时间】:2018-01-26 22:11:41
【问题描述】:

这行代码:

if !FileManager.fileExists(atPath: documentDirectory.appendingPathComponent("newname.pdf"))

收到错误提示

'fileExists' 产生 'Bool',而不是预期的上下文结果类型 '布尔'

在 Xcode 9.2 上。我错过了什么?

【问题讨论】:

    标签: swift nsfilemanager


    【解决方案1】:

    您需要在 FileManager 的实例上调用 fileExists。这不是类方法。

    FileManager 提供了在大多数情况下使用的default 实例。

    if !FileManager.default.fileExists(atPath: documentDirectory.appendingPathComponent("newname.pdf"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多