We all know that as soon we drop an outlet inside a View or its ViewController, it is being marked as unwrapped and we all know that Swift wants to initialise all the properties within the initialisation phase and this is the sentence we give to whoever asks us for the first time why an outlet is always in company with the exclamation mark.
Today I was trying to understand why an object that comes from a XIB, cannot be initialised within the initWithCoder:
method.
As far as I know, a XIB file just contains all the information about the objects drawn internally at the XIB using an XML file structure. So what we see inside the XIB file is gonna be archived and stored into a file.
When we will call the UINib
loadNibNamed:owner:options:
class method, it will unarchive the object created previously, look up for all the properties, set them and send the message awakeFromNib
to the object...
but due to that exclamation mark that says "During the init phase I'm not able to init you" what I've said above should be incorrect.. But why? Can someone tell me why Nib cannot be init and should be marked as optional?
Here I have some docs from Apple that didn't help me https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html