【问题标题】:Property 'representedObject' with type 'AnyObject?' cannot override a property with type 'Any?'类型为“AnyObject?”的属性“representedObject”无法覆盖类型为“任何?”的属性
【发布时间】:2016-10-25 04:38:29
【问题描述】:

我在尝试将以下代码升级到 Swift 3 时遇到了问题。

我该如何解决这个问题?

   @IBAction func Quit(_ sender: AnyObject) {
        NSApplication.shared().terminate(self)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        //INSERT DATE & TIME
        labeldate.stringValue = DateFormatter.localizedString(from: Date(), dateStyle: DateFormatter.Style.full, timeStyle: DateFormatter.Style.none)

    }

    override var representedObject: AnyObject? {
        didSet {
            // Update the view, if already loaded.
        }

上面写着:

类型为“AnyObject?”的属性“representedObject”无法覆盖类型为“任何?”的属性

我可以用什么代替?

【问题讨论】:

  • 在 swift 3 AnyObject 被替换为 Any
  • 读取错误。然后查看 representedObject 变量的 Swift 3 文档。变化变得明显。

标签: swift cocoa swift3


【解决方案1】:

您需要在代码中更改以下内容

 override var representedObject: Any? {
   didSet {
        // Update the view, if already loaded.
   }
 }

【讨论】:

    猜你喜欢
    • 2013-04-05
    • 2018-08-31
    • 2019-09-29
    • 1970-01-01
    • 2019-08-12
    • 1970-01-01
    • 2021-09-23
    • 2019-06-12
    • 1970-01-01
    相关资源
    最近更新 更多