1、枚举的定义:使用ENUM关键词把它们整个定义放在一对大括号内
enum SomeEumeration
{
//enumeration definition goes here
}
2、枚举的使用:
enum Gender
{
case Male
case Female
}
let ww
{
case .Male:
print("nan ren")
case Gender.Female:
print("nv ren")
}
3、枚举的关联值:
enum Gender
{
case Male(string)
case Femla(int , string )//表示可以关联任意类型,每个case关联的的数据可以不一样
}
let wd=Gender.Male("男")
switch wd
{
case .Male(let x):
print("zhe shi yi ge \(x)")
case.Female:
Print("nv ren")
}
let hy=Gender.Female(19,"zhang")
swich wd
{
case.Male(let x):
print("zhe shi yi ge \(x)")
case let.Female(x,y)://相当于x与y都是let
print("nv ren")
}
4、原生值
//原生值,所有原生值都必须唯一
enum Status:int
{
case UnApproved
case Approved
case X=5 //=1就报错
case Y
case A
}
let goods=Status.Approved
goods.rawValue
原文:http://www.cnblogs.com/tyty/p/4937278.html