Declaring enumerations
enum Direction { case North case East case West case South}
You can also use a case
enum Direct { case North, East, South}
Using enumerations
var dirct = Direction.East.West
Related values
You can use an enumeration to store any related reference
enum PersonInfo { case Age(Int) case Name(String)}
var person = PersonInfo.Name("ttf")switch person {case .Age(let age)://获得这个值 print("person‘s age is \(age)")case .Name(let name): print("person‘name is \(name)")}
Enumeration with initial values
/**以字符为初始值的枚举*/enum DirWithChar: Character { case"\t" case"\n" case"\0" case"\r"}
/**以Int为初始值的枚举*/enum DirWithInt: Int { case0 case West case East case South}
Get the initial value
let dirValue = DirWithInt.East.rawValue
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Swift-Summary" enumeration