Swift NSKeyedArchiver toFile:未解析的标识符

Swift NSKeyedArchiver toFile: Unresolved Identifier

当我试图让我的 NSCoding 代码工作时,保存自定义对象数组时,'path' 表示它尚未解决。我试图将它用作字符串 "path" 但该方法不应该将其作为字符串使用。我做错了什么?

错误:

Use of unresolved identifier 'path'

// After Updating Table, Save Arrays
var success = false

success = NSKeyedArchiver.archiveRootObject(mainArray, toFile: path)

if success {
    print("Saved Blogs")
} else  {
    print("Didn't Save Blogs")
}

ViewDidLoad

override func viewDidLoad() {
    super.viewDidLoad()

    // NSCoding
    var path : String {
        let manager = FileManager.default
        let url = manager.urls(for: .documentDirectory, in: .userDomainMask).first! as NSURL
        return url.appendingPathComponent("blogs.plist")!.path
    }
}

确保在调用方法的同一范围内定义变量。