我试图从模型类访问一个枚举,以编写一个切换案例来执行segue。这是我的代码:
class LandingViewController: UIViewController {
// MARK: Private Structs.
private struct SegueIdentifier {
static let forcedUpdate = "forcedUpdate"
static let optionalUpdate = "optionalUpdate"
}
// MARK: Private variables.
private let updateType: StartupManager.UpdateType
// MARK: LifeCycle Methods.
override func viewDidLoad() {
super.viewDidLoad()
StartupManager.setupForLanding()
var segueIdentifier: String
switch updateType {
case .ForcedUpdate: segueIdentifier = SegueIdentifier.forcedUpdate
case .OptionalUpdate: segueIdentifier = SegueIdentifier.optionalUpdate
}
performSegueWithIdentifier(segueIdentifier, sender: nil)
}
将setupForLanding()
被用于检查startUpManager模型类,看看哪个枚举被触发。
class StartupManager: NSObject {
enum UpdateType {
case OptionalUpdate
case ForcedUpdate
}
// code to perform a check
if isForceUpdate {
completion(.ForcedUpdate)
} else {
completion(.OptionalUpdate)
}
但是我不断收到错误消息LandingViewController has no initialisers
。如何在启动管理器中签入哪种情况,然后在landingViewController中执行segue?
您必须初始化updateType的值
private let updateType:StartupManager.UpdateType = .OptionalUpdate例如
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句