Swift 4 - not allow to override autosavesInPlace

Using XCode 9 beta 2, migrating from swift 3.2 to swift 4.


For a NSDocument sub class.


Compiling error "Method does not override any method from its superclass"


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


Would you please help to let me know the solution?


Thanks

Accepted Reply

Are you sure it's a class method and not a property ?


Doc h ttps://developer.apple.com/documentation/appkit/nsdocument/1515106-autosavesinplace states :

class var autosavesInPlace: Bool { get }

Replies

Are you sure it's a class method and not a property ?


Doc h ttps://developer.apple.com/documentation/appkit/nsdocument/1515106-autosavesinplace states :

class var autosavesInPlace: Bool { get }

Thanks much @Claude31


Get it fixed by changing from a function to a property. The old code did work with swift BEFORE 4.0

FWIW, in situations like this, you can often figure out the answer by starting to type a new declaration in your class (typing "autos" would be enough) and let Xcode insert the correct override via autocompletion. That will show you what's different about the correct one.


The reason this became an error is that in Swift 4, a lot of properties that translated from Obj-C (in the SDK) to Swift as parameterless functions were fixed to translate as properties.


In Obj-C, a property getter is a method with the same name, but there are two different declaration syntaxes. Older Obj-C header files used the old syntax style, which prevented Swift from recognizing them as properties. Many of these which had been overlooked before were fixed in Swift 4.

I have the same problem, have you solved it,and how to solved it,Thanks