[swift-evolution] ternary operator ?: suggestion

Charles Constant charles at charlesism.com
Wed Dec 23 04:35:52 CST 2015


> In the case where your input is hashable, you could just do:
>
> let i = [.Red:0xff0000, .Green:0x00ff00, .Blue:0x0000ff][color]

Mea culpa: you were correct, this actually *does* work in a Playground, as
long as you access it when you construct it.

I didn't realize Swift was smart enough to infer a one-off Dict by its key.
Thanks Lattner & co! That is extremely cool :)

So that just leaves the fact that the Keys need to be hashable / not
optional.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151223/325dfc2c/attachment.html>


More information about the swift-evolution mailing list