我正在完成IOS Swift教程"FoodTracker",但是有一个错误我可以找到解决方案,我不知道哪里出了问题以及如何修复:
错误:
元组类型'()‘的值没有成员“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")有人能帮我吗拜托?
发布于 2017-11-05 21:51:39
代码是正确的,不应该有任何错误。尝试在ArchiveUrl上显式设置类型,例如:
static let ArchiveUrl: URL = DocumentsDirectory.appendingPathComponent("meals")https://stackoverflow.com/questions/47126694
复制相似问题