简体   繁体   中英

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

In a macOS project I use autosavesInPlace in this way:

import Cocoa

class Document: NSDocument {

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

}

This worked until the project was in Swift 3.2 but when updating the project in Swift 4, I get this error:

Method does not override any method from its superclass

How can I fix this?

Since Swift 4 autosavesInPlace is a property (not a function), so you should override in this way:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM