Intro
I am trying to debug my program and I have come across a problem. I am getting the swift error: Unexpectedly found nil while unwrapping an optional value.
This problem is from an implicitly unwrapped optional. The error is in ViewControllerB's init?(aDecoder:)
and the place where I set the value is in ViewControllerA's prepareForSegue(_:sender:)
that uses a "show segue" to go to ViewControllerB.
Problem
This leads me to beleive that the init?(aDecoder:)
method in ViewControllerB is called before the prepareForSegue(_:sender:)
in ViewControllerA. Am I right?
答案 0 :(得分:3)
Yes. An object is always initialised before it can be used elsewhere in the application.
If there is work you need to do that depends upon the property being set, it's often appropriate to trigger that work from a didSet
observer on the property or in the viewDidLoad()
method.