Swift Learning II

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.