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

Amir Michail a.michail at me.com
Sat Feb 27 08:47:09 CST 2016


> On Feb 27, 2016, at 9:46 AM, Ross O'Brien <narrativium+swift at gmail.com> wrote:
> 
> How is this different from the rejected ??= proposal?
> 

If the value is not nil, the program stops with an assertion error.

> On Sat, Feb 27, 2016 at 2:34 PM, Amir Michail via swift-evolution <swift-evolution at swift.org <mailto: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 <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160227/f0abdb8e/attachment.html>


More information about the swift-evolution mailing list