IOS 食物跟踪器教程:元组类型"()"的值没有成员"路径"



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

错误:

元组类型"()"的值没有成员"路径"

下面的代码中,变量"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")

最新更新