0

i have pop up viewController which has a textField, label and button to get input from user at requited time presented using ModelPresentation and capturing values using closures.

it works fine in most of the locations. but in only one calling its crash while supplying value for the UIelements showing the error found nil while unwrapping optional value.

what is the reason behind this?

called the function many places in the program. everyplace it shows. error happens at that specific place only

  • How do you present (guess is initialize) that ViewController? – Larme Mar 22 '22 at 16:50
  • If you edit your question to show the code path that crashes, including how you create (initialize) the view controller, we can re-open it and help you. My guess is you have a line that looks like `let aVC = MyViewController()`. If you do that, and your view controller's views are defined in a storyboard, the views won't load and your outlets will all be nil. – Duncan C Mar 22 '22 at 17:28
  • @DuncanC, As i have told it works everywhere else that specific location. consider that my error location is B, I copy the code from location A where it works perfectly to B, it shows nil but the code works fine everywhere else – Jose Jacob Mar 23 '22 at 08:22
  • If you don't show anything, it's hard to tell why it fails... – Larme Mar 23 '22 at 08:50
  • i figured it out. the object was created before the current viewController was loaded in to the display. so the object created was behind the in the VC hierarchy. due to the fact that its shown after the current VC is shown the pop doesn't contain a object reference and a new VC instance was created by itself and it was shown. calling the code in dispatchQueue solved it – Jose Jacob Mar 23 '22 at 09:17

0 Answers0