【发布时间】:2015-02-21 10:04:00
【问题描述】:
考虑以下带有委托的控制器类:
@objc protocol FooControllerDelegate {
}
@objc class FooController: UIViewController {
var delegate: FooControllerDelegate
init(delegate: FooControllerDelegate) {
self.delegate = delegate
super.init(nibName: nil, bundle: nil)
}
// TODO: How do we forbid this init?
required init(coder aDecoder: NSCoder) {
// TODO: Fails to compile.
super.init(coder: aDecoder)
}
}
有什么方法可以禁止使用 -initWithCoder: 等价物,而不使委托隐式解包,并在方法中放置 assert(false)?
理想情况下,根本没有必要为每个子类编写init(coder:),并且隐式禁止它。
【问题讨论】:
标签: ios xcode swift uiviewcontroller