Zack Zack - 1 year ago 96
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
Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download