You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pablo Villar edited this page Mar 20, 2017
·
3 revisions
Variables must always be defined with an appropriate optionality, following what's described in this blogpost.
Example
Good
@IBOutlet weak vartitleLabel:UILabel!self.titleLabel.text ="Something"
// If `titleLabel` is `nil`, app will crash at runtime, making it obvious that the developer is forgetting to hook it up in the Interface Builder.
Bad
@IBOutlet weak vartitleLabel:UILabel?iflet label =self.titleLabel {
label.text ="Something"}
// Conceptually wrong. Developer may forget to hook `titleLabel` in Interface Builder and that mistake could easily make it to a production stage without being noticed.
Motivation
It helps catch bugs earlier in the development stage.
Variables meaning and their intentions are clearer.