Swift, two issues. 1) weak var 2) bang operator for @IBOutlet Swift, two issues. 1) weak var 2) bang operator for @IBOutlet swift swift

Swift, two issues. 1) weak var 2) bang operator for @IBOutlet


  1. Swift IBOutlet are weak by default (but others properties are strong by default). So both writing are the same.

You have more details about the difference between weak and strong here

  1. According to apple documentation

When you declare an outlet in Swift, you should make the type of the outlet an implicitly unwrapped optional (!). This way, you can let the storyboard connect the outlets at runtime, after initialization.


The outlets are weak since the view elements are owned (strongly) by the view. I think it's technically OK for your view controller to have a strong reference too, but not necessary.

Weak variables are optional since they can be nil. You can declare your outlets with ? instead but that means using force-unwrapping or optional binding every time. Declaring them as implicitly-unwrapped optionals with ! is just a convenience.


You use weak when referring to IBOutlets because so long as the object remains in its superview there will be a strong reference to it. See weak or strong for IBOutlets. Next, the bang operator indicates that the IBOutlet is an explicitly unwrapped label. With the bang operator, it guarantees that the object will exist, so when referencing it, you can simply reference it like this:

someLabel.text = "some text"

However, you can make them IBOutlets optional:

@IBOutlet weak var someLabel: UILabel?

But you must use ? when accessing them

someLabel?.text = "some text"