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
}
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/3d388d19b4bc44c0824c6f2bbfc19d6f.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBATW9ycmlzXw==,size_20,color_FFFFFF,t_70,g_se,x_16)
修改如下:
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