Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Property 'self.navigation' not initialized at super.init call

How do I open a ViewController from @IBAction. In below @IBAction I tried to open a ViewController but I am getting Property 'self.navigation' not initialized at super.init call error:

 // MARK: - IBActions
    @IBAction func doAddCard() {
        // OTHER CODE GOES HERE
        
        let viewController = PaymentsStoryboard.confirmKyc()
        navigation.pushViewController(viewController, animated: true)
        
       //...    
}

Full Code:

import UIKit

final class ManualCardAddView: UIView, XibInitializable, DialogKeyboardDelegate {
    
    var completionHandler: ((CreditCard, String) -> Void)?
    private unowned let navigation: UINavigationController
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setup()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setup()
    }
    
    private func setup() {
        loadFromXib()
        
        // ...
    }
    
    @IBAction func doAddCard() {
        
        let viewController = PaymentsStoryboard.confirmKyc()
        navigation.pushViewController(viewController, animated: true)
        
        // ...
    }
}

How do I resolve above issue?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank You!

>Solution :

You need to change navigation to a mutable optional property, since it only gets set after the initialisation. All immutable properties (and mutable non-optional ones as well) must be set during initialisation.

So change

private unowned let navigation: UINavigationController

to

private unowned var navigation: UINavigationController?
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading