Swift making IBOulet as strong

You can make an IBOutlet strong by either selecting strong when connecting the outlet: enter image description here

Or just remove the weak keyword from the declaration:

@IBOutlet var label: UILabel!

As of Xcode 6 beta 2, Swift does not have a way to designate strong outlets. The workaround is to connect the outlet in IB, then remove the @IBOutlet attribute from your source file.

Update: This has been added in Xcode 6 beta 3.


Its now an option when creating the outlet from a drop down.

Here is why we might want to start making them strong from WWDC 2015 Session 407

http://asciiwwdc.com/2015/sessions/407

And the last option I want to point out is the storage type, which can either be strong or weak.

In general you should make your outlet strong, especially if you are connecting an outlet to a sub view or to a constraint that's not always going to be retained by the view hierarchy.

The only time you really need to make an outlet weak is if you have a custom view that references something back up the view hierarchy and in general that's not recommended.

So I'm going to choose strong and I will click connect which will generate my outlet.

Tags:

Ios

Macos

Swift