【问题标题】:Can't find FileManager Swift class in Foundation, where is it?在 Foundation 中找不到 FileManager Swift 类,它在哪里?
【发布时间】:2016-11-11 16:05:16
【问题描述】:

Apple 文档讨论了 Swift 类 FileManager,但 Xcode 并未将其识别为 Foundation 的一部分,我收到以下错误。那么这门课在哪里呢?

上面写着Use of unresolved identifier 'FileManager'。 我认为这是一个可以取代 NSFileManager 的新 API。

顺便说一句,讨论它的应用程序文档在这里: FileManager class

【问题讨论】:

  • 请添加产生错误的代码并完整添加错误信息。

标签: swift nsfilemanager


【解决方案1】:

我认为是 NSFileManager()

let fileManager =  NSFileManager.defaultManager()

【讨论】:

  • 在 Swift 2 中是 NSFileManager,在 Swift 3 中是 FileManager。
【解决方案2】:

您需要在使用 FileManager 类之前“导入 Foundation”。

import Foundation

let fileManager = FileManager()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-14
    • 2012-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多