[swift-evolution] Optional dictionary subscripts

Félix Cloutier felixcca at yahoo.ca
Tue Dec 22 12:33:58 CST 2015


if let value = map(key) { dict($0) }

Félix

> Le 22 déc. 2015 à 13:00:45, Erica Sadun via swift-evolution <swift-evolution at swift.org> a écrit :
> 
> if let key = key, value = dict[key] {
>    ...whatever...
> }
> 
> seems to work fine without introducing a new construct
> 
> -- E, waving hi to John 
> 
> 
>> On Dec 22, 2015, at 4:37 AM, John Holdsworth via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> This isn’t the most compelling of ideas but a couple of times I’ve found myself writing:
>> 
>> if let value = key != nil ? dict[key] : nil {…
>> 
>> and was wondering if the syntax could be:
>> 
>> if let value = dict[key?] {…
>> 
>> The key for dictionaries could be made optional in stdlib but this is probably best implemented in the compiler for safety.
>> 
>> Cheers
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> _______________________________________________
> 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