Zack Zack - 7 months ago 27
iOS Question

Is init?(aDecoder:) or prepareForSegue(_:sender:) called first?


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
and the place where I set the value is in ViewControllerA's
that uses a "show segue" to go to ViewControllerB.


This leads me to beleive that the
method in ViewControllerB is called before the
in viewControllerA. Am I right?

Jim Jim

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.