[swift-evolution] Optional dictionary subscripts

Erica Sadun erica at ericasadun.com
Tue Dec 22 12:00:45 CST 2015


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



More information about the swift-evolution mailing list