IBOutlet is nil, but it is connected in storyboard, Swift

Typically this happens because your view controller hasn’t loaded its view hierarchy yet. A view controller only loads its view hierarchy when something sends it the view message. The system does this when it is time to actually put the view hierarchy on the screen, which happens after things like prepareForSegue:sender: and viewWillAppear: have returned.

Since your VC hasn’t loaded its view hierarchy yet, your outlets are still nil.

You could force the VC to load its view hierarchy by saying _ = self.view.

Leave a Comment