This is less desirable than ??= would have been. To summarise the two
lhs ??= rhs. lhs is an Optional<T>, rhs is a T or Optional<T>.
If lhs is nil, assign to lhs the value of rhs. If lhs is not nil, do
lhs := rhs. lhs is an Optional<T>, rhs is a T or Optional<T>.
If lhs is nil, assign to lhs the value of rhs. If lhs is not nil, crash
with an assertion error.
The ??= operator is safer; its behaviour is clear and it doesn't cause my
code to crash. := is more dangerous; if I want to be sure my app won't
crash, I now need to check whether lhs is nil first... and if I do that, I
might as well use the = operator.
I don't see what advantages your operator brings to Swift, or why you think
it should be accepted when ??= operator was rejected.
On Sat, Feb 27, 2016 at 2:47 PM, Amir Michail <email@example.com> wrote:
On Feb 27, 2016, at 9:46 AM, Ross O'Brien <firstname.lastname@example.org> > 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 < > email@example.com> 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