Swift Property ‘self.xxx‘ not initialized at super.init call

Swift Property ‘self.xxx‘ not initialized at super.init call,第1张

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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/993735.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-21
下一篇2022-05-21

发表评论

登录后才能评论

评论列表(0条)

    保存