如何更新 iOS 中覆盖 supportedInterfaceOrientations 函数的旧 Swift 代码?
How do I update old Swift code in iOS that overrides supportedInterfaceOrientations function?
我在 Swift 3 中有用于 iOS 的旧 Swift 代码,它覆盖了函数 supportedInterfaceOrientations。我收到一条错误消息:
Method does not override any method from its superclass
现在该函数已成为变量。
当我尝试覆盖变量时,我收到一条错误消息:
Cannot override with a stored property 'supportedInterfaceOrientations'
如何更新旧的 Swift 代码?当函数成为新框架中的变量时,这个问题应该适用于任何情况。
当我选择像这样的代码为超类赋值时:
override func viewDidLoad() {
super.viewDidLoad()
supportedInterfaceOrientations = .all
}
我收到一条错误消息,指出 supportedInterfaceOrientations
是一个只获取变量。
如何更新这个旧代码?
要更新您的代码,您应该创建 var 的覆盖并使其 return 成为所需的值。例如,对于 supportedInterfaceOrientations,它应该成为下面的变量。
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .all
}
我在 Swift 3 中有用于 iOS 的旧 Swift 代码,它覆盖了函数 supportedInterfaceOrientations。我收到一条错误消息:
Method does not override any method from its superclass
现在该函数已成为变量。
当我尝试覆盖变量时,我收到一条错误消息:
Cannot override with a stored property 'supportedInterfaceOrientations'
如何更新旧的 Swift 代码?当函数成为新框架中的变量时,这个问题应该适用于任何情况。
当我选择像这样的代码为超类赋值时:
override func viewDidLoad() {
super.viewDidLoad()
supportedInterfaceOrientations = .all
}
我收到一条错误消息,指出 supportedInterfaceOrientations
是一个只获取变量。
如何更新这个旧代码?
要更新您的代码,您应该创建 var 的覆盖并使其 return 成为所需的值。例如,对于 supportedInterfaceOrientations,它应该成为下面的变量。
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .all
}