Search code examples
swiftmacosmigrationnsdocument

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?


Solution

  • 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
       }
    }