Created
December 16, 2016 08:48
-
-
Save josephchang10/6dda34336869d1e8bff0c0742a143f16 to your computer and use it in GitHub Desktop.
枚举
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
enum China: Int { | |
case Guangzhou = 0 | |
case Beijing | |
var description: String { | |
switch self { | |
case .Guangzhou: | |
return "广州" | |
case .Beijing: | |
return "北京" | |
} | |
} | |
} | |
class City { | |
var name = China.Guangzhou | |
} | |
let guangzhou = City() | |
print(guangzhou.name.description) | |
// 直接输出enum的值 | |
print(China.Guangzhou.description) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
通过enum,既可以提高代码的可读性,也可以提高代码的效率。