IOS FoodTracker 教程 : Value of tuple type '()' has no member 'path'

标签 ios swift

我正在完成 IOS Swift 教程“FoodTracker”,但是有一个错误我可以找到解决方案,但我不明白哪里出了问题以及如何解决它:

错误:

Value of tuple type '()' has no member 'path'

此错误在以下代码中针对变量“Meal.ArchiveUrl.path”显示。

我的代码,在 MealtableViewController(相当于 IOS 教程):

private func saveMeals(){
    let isSuccessfulSave = NSKeyedArchiver.archiveRootObject(meals, toFile: Meal.ArchiveUrl.path )

    if isSuccessfulSave {
        os_log("Meals successfully saved.", log: OSLog.default, type: .debug)

    } else {
        os_log("Failed to save meals...", log: OSLog.default, type: .error)

    }
}

在 Meal.swift 中,有声明:

/MARK: Archiving Paths
static let DocumentsDirectory = FileManager().urls(for: .documentDirectory, in: .userDomainMask).first!
static let ArchiveUrl = DocumentsDirectory.appendingPathComponent("meals")

有人可以帮我解决这个问题吗?

最佳答案

代码正确,应该没有错误。尝试在 ArchiveUrl 上显式设置类型,例如:

static let ArchiveUrl: URL = DocumentsDirectory.appendingPathComponent("meals")

关于IOS FoodTracker 教程 : Value of tuple type '()' has no member 'path' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47126694/

相关文章:

html - 使上一个/下一个按钮在 iOS 上的复选框上起作用

arrays - 自 iOS 14.5 以来,新的 `filter(_:)` 数组方法是什么?

ios - 如何使用目标使用相同的代码库启动多个应用程序?

swift - 处理 Observable.subscribe 的结果时不调用 OnNext

ios - iPad 中 PopoverView 中的 UIDatePicker

ios - 返回错误的设备方向

ios - 在 UITableView 上使用 UserDefaults

ios - AVPlayer 在 302 重定向后无法为同一域发送 cookie

ios - Swift:无法修改弹出窗口中的图像

swift - 在 Xcode 9 Swift 3 Watch 应用程序中安装 Alamofire