如何更新iOS中覆盖了supportedInterfaceOrientations函数的旧Swift代码?

时间:2019-04-20 21:45:47

标签: ios swift uiviewcontroller

我在iOS的Swift 3中有旧的Swift代码,它覆盖了supportedInterfaceOrientations函数。我收到一条错误消息:

  

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

现在该函数已被设置为变量。

当我尝试覆盖变量时,出现错误消息:

  

无法使用存储的属性“ supportedInterfaceOrientations”覆盖

如何更新旧的Swift代码?当函数成为新框架中的变量时,该问题应适用于任何情况。

当我选择改为将值分配给超类时,如下所示:

override func viewDidLoad() {
    super.viewDidLoad()

    supportedInterfaceOrientations = .all

}

我收到一个错误消息,说supportedInterfaceOrientations是仅获取变量。

如何更新此旧代码?

1 个答案:

答案 0 :(得分:1)

要更新代码,您应该创建var的替代并使其返回所需的值。例如,对于supportedInterfaceOrientations,它应该成为下面的变量。

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .all
}