【问题标题】:Migrating from Swift 3.2 to Swift 4 I get an error using autosavesInPlace从 Swift 3.2 迁移到 Swift 4 使用 autosavesInPlace 时出现错误
【发布时间】:2018-01-03 12:39:22
【问题描述】:

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

import Cocoa

class Document: NSDocument {

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

}

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

方法不会覆盖其超类中的任何方法

我该如何解决这个问题?

【问题讨论】:

    标签: swift macos migration nsdocument


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多