从 Swift 3.2 迁移到 Swift 4 我在使用 autosavesInPlace 时遇到错误

Migrating from Swift 3.2 to Swift 4 I get an error using autosavesInPlace

在 macOS 项目中,我以这种方式使用 autosavesInPlace:

import Cocoa

class Document: NSDocument {

    override class func autosavesInPlace() -> Bool {
        return true
    }

}

这一直有效,直到项目在 Swift 3.2 中,但是在 Swift 4 中更新项目时,我收到此错误:

Method does not override any method from its superclass

我该如何解决这个问题?

因为 Swift 4 autosavesInPlace 是一个 属性 (不是函数),所以你应该这样重写:

class Document: NSDocument {
   override class var autosavesInPlace: Bool {
     return true
   }
}