IBOutlet is nil, but it is connected in storyboard - fatal error: unexpectedly found nil while unwrapping an Optional value

hi,


I just made uiview in one uiviewcontroller , and connect them well.

(IBOutlet is nil, but it is connected in storyboard)


and there is error when i get frame of that uiview.


@IBOutlet weak var homecv : UIView!



and



override func viewDidLoad() {

super.viewDidLoad()

print("home ", homecv.frame) -> here is error : fatal error: unexpectedly found nil while unwrapping an Optional value


}

Same result happend even in viewDidAppear ... I cleaned project.. it is same too..

Any idea for this ?😎

Replies

I test your code and it works ok, the only thing that can happens is that your IBOutlet is not configure right in the storyboard, check in Interface Builder your IBOutlet.

I have similar problem and found that if I resize the control, it will then work.


Then everything will work until you modify the controls (labels, textbox, text views etc) again.


Then if you resize any of them, sometimes have to do it a few times, then it works again.


Don't know why. Suspect it's a bug in Xcode.