Sorry -1 from me. Not worth adding. Too few use cases. <span></span><br><br>On Sunday, 28 February 2016, Brent Royal-Gordon via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">&gt; Here’s a use case. Suppose you are filling out a dictionary in some non-trivial way. However, it should be the case that the value for each key is computed and assigned only once. And so you would use the := operator to ensure this: dictionary[k] := value<br>
<br>
This is actually a great use case, and it&#39;s exactly the kind of thing you should mention when you suggest a change to Swift.<br>
<br>
However, I think that specific use case is better served by a method on Dictionary. Perhaps something equivalent to:<br>
<br>
        mutating func initializeValue(value: Value, forKey key: Key) {<br>
                let oldValue = updateValue(value, forKey: key)<br>
                precondition(oldValue == nil, &quot;Initialized \(key) when it was already set&quot;)<br>
        }<br>
<br>
Why do I think this approach is better?<br>
<br>
* `:=` doesn&#39;t really explain what it does—if you&#39;ve never seen the operator before, the most you can be sure of is that it&#39;s probably some kind of assignment. `initializeValue(_:forKey:)` *does* explain the intended semantic—this should set a value for the first time—which suggests that it shouldn&#39;t be used with a value that&#39;s already set.<br>
<br>
* I would need to see compelling examples of `:=` used outside of Dictionaries before I thought it would be useful as something applied to any lvalue. Dictionary is an unusual case because they have a dynamically-determined set of keys which are created simply by assigning them, so it&#39;s reasonable to not know whether a particular key is `nil` or not. Swift variables and properties, and most Swift collections, separate adding a value from updating it, so they may not need an analogous operation.<br>
<br>
* By putting the precondition inside `initializeValue(_:forKey:)` itself, the error message can actually include the key, which may aid in debugging.<br>
<br>
--<br>
Brent Royal-Gordon<br>
Architechies<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="javascript:;" onclick="_e(event, &#39;cvml&#39;, &#39;swift-evolution@swift.org&#39;)">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote><br><br>-- <br>-- Howard.<br>