[swift-evolution] Remove default case in switch-case
Chris Lattner
clattner at apple.com
Wed Dec 9 17:06:16 CST 2015
> On Dec 9, 2015, at 3:01 PM, Mustafa Yusuf via swift-evolution <swift-evolution at swift.org> wrote:
>
>
> Hello all. In switch statements in swift if all the possible cases aren't covered we have to supply a default case.
>
> let number = 10
>
> switch number {
> case 10: print("yay")
> case 12: print("close")
> default: print("try again")
> }
>
> My proposal is replace it with the "case _:".
>
> let number = 10
>
> switch number {
> case 10: print("yay")
> case 12: print("close")
> case _: print("try again")
> }
>
> Since underscore in swift means "whatever I don't care" it suits here better than "default". Correct me If I am wrong but this is the only use for "default" keyword in swift I guess. So we can completely remove "default" keyword from the language.
>
FWIW, this is already supported. We *also* support default for clarity of code / because it reads better, and for similarly with the (extended) C family of languages.
-Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151209/f034bb03/attachment-0001.html>
More information about the swift-evolution
mailing list