Use enum
-to-create an enumeration. Like classes and all other named types, enumerations can has methods associated with them.
The enum in swift changes a lot, and the enumeration looks similar to the class because it can have its own method, and the enum is created as follows
Enum Rank:int {
Case ACE = 1
Case A, three, four, Five, Six, Seven, Eight, Nine, Ten
Case Jack, Queen, King.
Func simpledescription (), String {
Switch self
{
Case. Ace:
Return "Ace"
Case. Jack:
Return "Jack"
Case. Queen:
Return "Queen"
Case. King:
Return "King"
Default
Return String (Self.rawvalue)
}
}
}
As can be seen in the example above, the type specified at the time of the creation is the int type, which can specify the initial value of the RawValue, and from the beginning of 0, the value of the values in Swift can also be a floating point value and a string.
In the example above, the Raw-value type of the enumeration Int
are, so that only has the to specify the first raw value. The rest of the raw values is assigned in order. You can also with strings or floating-point numbers as the raw type of an enumeration. Use the property to rawValue
access the raw value of a enumeration member.
As you can see, Swift has a great language flexibility, and using rank (RawValue: < #Int #>) to get a optional that needs to be unpacked before it can be used. The use of enums is relatively simple, with examples and official documents that are easy to grasp. I learn iOS time is shorter, the blog is not the right place to ask you to do a lot of administration.
Swift re-identification of enumeration variables