我正在完成 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/