1. Enumeration
Create an enumeration using the keyword enum.
The default starting value of the enumeration is 0, and you can customize the starting value.
A method can be defined in an enumeration, as defined in a class.
Accesses the value of the current enumeration using the keyword RawValue.
enumRank:int { CaseAce =1 CaseThree, four, five, six, seven, eight, nine, ten CaseJack, Queen, King Func simpledescription ()-String {SwitchSelf { Case. Ace:return "Ace" Case. Jack:return "Jack" Case. Queen:return "Queen" Case. King:return "King" default: returnString (Self.rawvalue)}} } Let Ace=Rank.ace let Acerawvalue= Ace.rawvalue
And also
if 3 ) { = convertedrank.simpledescription () }
And also
enumSuit { CaseSpades, Hearts, diamonds, clubs func simpledescription ()-String {SwitchSelf { Case. Spades:return "Spades" Case. Hearts:return "Hearts" Case. Diamonds:return "Diamonds" Case. Clubs:return "Clubs"}}} let hearts=suit.hearts let Heartsdescription= Hearts.simpledescription ()2 Structural bodies
Use the keyword struct to create the struct body.
Structs and classes are similar, including methods and initialization. The biggest difference between a struct and a class is that the struct is a copy of the value during the pass, and the class is a reference copy.
struct Card { var rank:rank var suit:suit - String { return' The \ (Rank.simpledescription ()) of \ (Suit.simpledescription ())" } } = Card (rank:. Three, suit:. Spades) = Threeofspades.simpledescription ()
Well, try.
Ios-swift-enumeration and struct body