Defining enumeration methods an enum Season {//Each case defines an instance of the Spring cases Summer-Fall-the-winter}//definition enumeration mode two enum WEEKDA Y {//Use a case to list all enumerated instances cases Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, sunday}//use enum declaration variable var day:wee KDAY//uses an existing enumeration instance to assign a value of day = Weekday.sundayday =. Wednesday//automatic inference for Weekday type//enumeration with the switch statement using var Chooseday = Weekday.saturdayswitch Chooseday {case. Monday:print ("Monday") case. Tuesday:print ("Tuesday") case. Friday:print ("Friday")//If all cases are not listed, a default processing Default:print ("Other day")}//original value/* will need to be added at the end to handle other cases. Enum enum Name: Original value type {Case enumeration value = original Value} */enum weekdayhasrawvalue:int {case Monday, Tuesday = 1, Wednesday = 5, Sund Ay}enum Seasonhasrawvalue:character {Case Spring = ' S ' case Summer = ' U ' case Fall = ' F ' case Winter = "W"}v Ar aday = Weekdayhasrawvalue.sundayprint (". The original value of Sunday is: \ (aday.rawvalue) ") var Myseason = Seasonhasrawvalue.init (rawValue:" S ")//The constructor that might fail, so the if let optional binding is used to judge IF Let s = Myseason {switch s {case. Spring:print ("Spring") default:print ("Not Spring")}}
Swift Learning II