[swift-evolution] Consolidate Code for Each Case in Enum

Anton Zhilin antonyzhilin at gmail.com
Sun Jan 8 02:42:01 CST 2017


It would be nice if for each enum case, there was a computed property
returning an optional. Then you could do:

enum FooBar {
    case foo(Int)
    case bar(Int)
}
let x = FooBar.foo(42)
x.foo  //=> Optional(42)
x.bar  //=> nil

This feature has been discussed many times, but each time it was considered
“out of scope”.
​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170108/8c38595d/attachment.html>


More information about the swift-evolution mailing list