1. Enumeration definition: Use the enum keyword to place their entire definition within a pair of curly braces
Enum Someeumeration
{
Enumeration definition goes here
}
2. Use of enumerations:
Enum Gender
{
Case Male
Case Female
}
Let WW
{
Case. Male:
Print ("Nan Ren")
Case Gender.female:
Print ("NV ren")
}
3. The associated value of the enumeration:
Enum Gender
{
Case Male (String)
Case Femla (int, string)//indicates that any type can be associated, and the data associated with each case can be different
}
Let Wd=gender.male ("male")
Switch WD
{
Case. Male (Let X):
Print ("Zhe shi Yi ge \ (x)")
Case. Female:
Print ("NV ren")
}
Let Hy=gender.female ("Zhang")
Swich WD
{
Case. Male (Let X):
Print ("Zhe shi Yi ge \ (x)")
Case Let. Female (x, y)://equals x and Y are let
Print ("NV ren")
}
4. Native value
Native value, all native values must be unique
Enum Status:int
{
Case Unapproved
Case approved
Case X=5//=1 on the error
Case Y
Case A
}
Let goods=status.approved
Goods.rawvalue
Swift enumeration Code