[swift-evolution] Proposal: An assignment operator := that ensures nil before assignment.

Amir Michail a.michail at me.com
Sat Feb 27 10:59:45 CST 2016


> On Feb 27, 2016, at 11:32 AM, Radosław Pietruszewski <radexpl at gmail.com> wrote:
> 
> Expressing the constraint of “can’t be nil” is much better done via the type system, where the undesirable value is simply impossible. Instead of inducing crashes with innocently-looking special operator, just use a non-optional variable, and where you have to convert from an optional, unwrap it explicitly.
> 

The constraint actually is “has to be nil”.

> — Radek
> 
>> On 27 Feb 2016, at 15:34, Amir Michail via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> Consider the use of “!” in the following:
>> 
>> var x: Int? = 5
>> 
>> x! = 2 // “!” is used to ensure non-nil value before assignment
>> 
>> The idea is to have a similar method for ensuring a nil value.
>> 
>> So instead of writing:
>> 
>> precondition( x == nil )
>> x = 3
>> 
>> You could write:
>> 
>> x := 3
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 



More information about the swift-evolution mailing list