简体   繁体   English

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

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

In a macOS project I use autosavesInPlace in this way: 在macOS项目中,我以这种方式使用autosavesInPlace:

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: 在项目在Swift 3.2中运行之前,它一直有效,但是在Swift 4中更新项目时,出现此错误:

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: 由于Swift 4 autosavesInPlace是一个属性(不是函数),因此您应该以这种方式覆盖:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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