//定义一个枚举 Direction 枚举字符名字 enum Direction{ case North case South case East case West }; enum Direction2{ case North, South, East, West } //声明一个枚举 var d = Direction.North; var d2 = Direction.East; var d3 :Direction = .West; // 相当于 C语言 的 自主赋值枚举 enum Course :Int { case android = 1, IOS = 2, WindowsPhone = 5 }
d2 = .South; //因为 d2 肯定 是 Direction 的一个枚举类型 所以可以这么写 switch d2 { case .North : print("north") break case .South : print("south") break default: print("others") } let c = Course.IOS var v = c.rawValue // 把枚举类型转换为 Int 类型 print("(v)")