SWIFT-39-Enum Type association default value

Source: Internet
Author: User

: Playground-noun:a place where people can playimport uikitenum month:int{    //So defined, after the Feb, Mar will automatically be assigned a value of 2 and 3    . Case Jan = 1, Feb, Mar, APR, May, June, July, Dec}let, Sep, Oct, Nov, Currentmonth:month =. nov//View the value of the enumeration currentmonth.rawvalue//the enumeration variable created by this method is a selectable variable. After unpacking, use let Nextmonth = Month (rawvalue:12) nextmonth!. rawvalue//example var userinputnumber = 0if Let Themonth = Month (rawvalue:userinputnumber) {    switch themonth {case    . J An:        print ("It's the first month") Case    . DEC:        print ("It's the last month")    default:        print ("It's the normal month")}    } else {    print ("ERROR" The default values associated with}//Swift are not just integers, but other types of enums such as strings, personnum:string{case One    = "RINPE" Case--"    Lili" Case    thre E = "Lolo"}//example let Userinput = "Rinpe" if Personnum (rawvalue:userinput)! = Nil {    print ("Welcome, \ (Userinput) professor")} else {    print ("Sorry, you are not an employee of the Company")}

  

Swift-39-Enum type association default

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.