Object init and Xib, Storyboard.


let view = UIView()
let viewController = UIViewContoller()

This is a basic init code.
but… if you make Xib, Storyboard.
you should init different way.

let nib = UINib(nibName: "View", bundle: nil)
let view = nib.instantiate(withOwner: nil, options: nil)[0] as! UIView

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewContoller = storyboard.instantiateViewController(withIdentifier: "ViewContoller") as! ViewContoller

And then… this is the point. even if you make view and viewContoller this way,
calling IBOutlet properties may be return none.

because, view and viewContoller hasn’t loaded its view hierarchy yet. (like lazy properties)
loads its view hierarchy only when something sends it a view message.
So here your outlets are may nil since it is not loaded yet.

just try to force your VC to call self.view and then access the properties/outlets.