When I create a label in the view (dragged from the Object library) and make the IBOutlet to connect the label and viewController (Ctrl and drag), The default code generated by Xcode is, for example,
@IBOutlet weak var displayColumn: UILabel!
You have created a label in Xcode and indicated to Xcode that you want that label connected to that
@IBOutlet. But that connection doesn't happen until later.
This is the order of events at runtime.
@IBActions are connected.
In Swift, when a class is instantiated, all properties must be initialized. In step 1, the outlets are
nil because they haven't been connected yet. In order to allow for this, they must be declared as Optionals.
It is perfectly valid to use a normal Optional, such as:
@IBOutlet weak var displayColumn: UILabel?
but then you'd have to deal with unwrapping it each time you access it. The only time an
@IBOutlet will be nil is when step 3 hasn't happened yet (for example, in
prepareForSegue) or if you forgot to connect the outlet or renamed it. In those cases, the crash caused by accessing
nil alerts you to the problem.