Correct me if I'm wrong, but `weak` reference can not be `let` just by definition: at some point in time such reference *can* become nil.

On 18.05.2016 16:22, Daniel Steinberg via swift-evolution wrote:
I would like to propose we modify the meaning of @IBOutlet in light of the 
accepted proposal SE-0054 Abolish ImplicitlyUnwrappedOptional type. I think 
this fits in with the current Swift 3 goals.

Currently we use “var” and “!” when we declare an outlet like this:

@IBOutlet weak var myLabel: UILabel!

The “!” in the declaration allows us to use the outlet like this without 
unwrapping it

myLabel.text = “Hello"

We use “var” and “UILabel!" because myLabel starts its life out as nil and does 
not have a value until the connection is made. i.e. myLabel must be an optional if 
it accepts nil and the type is UILabel! instead of UILabel? so that we don’t have to 
unwrap it each time we use it.

If we break the connection to the UILabel instance we crash at runtime for 
attempting to unwrap nil.

Given this, I propose that we be able to write

@IBOutlet weak let myLabel: UILabel

In this case @IBOutlet has a meaning somewhat similar to lazy - it’s not that 
myLabel doesn’t exist until we first call it, but @IBOutlet indicates that 
myLabel should exist before we call it.

If the connection isn’t made and myLabel doesn’t exist, we should crash as we 
do now. If the connection is not made in the nib or storyboard, this will crash 
at development time.

This removes a case in which we use var - not because we want to change the 
value of a property but because of a detail in the tooling.

This change also removes a case in which we use an Optional again for a detail 
in lifecycle and tooling.

Best,

Daniel
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to