Swift重写父类的init方法时,报了如下错误。
Property 'self.xxx' not initialized at super.init call
大概意思是在调用父类init方法前,需要给属性赋值。
报错代码
required init(leftController: UIViewController?, centerController: UIViewController) {
super.init(nibName: nil, bundle: nil)
self.centerController = centerController
if (leftController != nil) {
self.leftController = leftController
}
}
修改如下:
required init(leftController: UIViewController?, centerController: UIViewController) {
self.centerController = centerController
if (leftController != nil) {
self.leftController = leftController
}
super.init(nibName: nil, bundle: nil)
}
See also:
【1】Property ‘self.*’ not initialized at super.init call:https://stackoverflow.com/questions/29890510/property-self-not-initialized-at-super-init-call