Last active
September 4, 2015 10:34
-
-
Save el-hoshino/175888dc5d1a3ee6d6b5 to your computer and use it in GitHub Desktop.
Swift での Int 型 switch case の落とし穴(?) ref: http://qiita.com/lovee/items/31bc2b4e66a93944c9a6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let a = 0 | |
switch a { | |
case Int.min ..< 0: | |
print("負数") | |
case 0: | |
print("零") | |
case 1 ... Int.max: | |
print("正数") | |
default: | |
fatalError("俺はプログラマをやめるぞ!") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case 1 ..< Int.max, Int.max: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case ClosedInterval(1 ... Int.max): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment