Skip to content

Instantly share code, notes, and snippets.

@josephchang10
Created December 16, 2016 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephchang10/6dda34336869d1e8bff0c0742a143f16 to your computer and use it in GitHub Desktop.
Save josephchang10/6dda34336869d1e8bff0c0742a143f16 to your computer and use it in GitHub Desktop.
枚举
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)
@josephchang10
Copy link
Author

通过enum,既可以提高代码的可读性,也可以提高代码的效率。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment