[swift-evolution] Colon vs. equals
Nate Cook
natecook at gmail.com
Sat Feb 6 11:37:32 CST 2016
> On Feb 6, 2016, at 10:11 AM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
>
>
>> on Sat Feb 06 2016, Haravikk <swift-evolution at swift.org> wrote:
>>
>> +1 for changing attributes to using colons, as it would make them read
>> more like a function call (albeit one with slightly different rules).
>>
>> -1 though for changing dictionary literals; personally I think the
>> colon syntax is a lot clearer, especially when the literal is being
>> assigned, as it means there is only a single, clear assignment.
>>
>> Regarding assigning new values to a dictionary though, I wonder if we
>> might extend the literal syntax to modifying an existing dictionary?
>> For example, I might do something like:
>>
>> myDictionary[“foo”: 1, “bar”: 2] // Add/set new values for foo and bar
>>
>> As this could be a neater way to replace:
>>
>> myDictionary[“foo”] = 1
>> myDictionary[“bar”] = 2
>
> This should be spelled
>
> myDictionary.updateValues([“foo”: 1, “bar”: 2])
>
> or maybe
>
> myDictionary.update([“foo”: 1, “bar”: 2])
There's a proposal for updating a dictionary in place using a dictionary literal, among other things: https://github.com/apple/swift-evolution/pull/125
Nate
More information about the swift-evolution
mailing list