Swift enumeration Code

Source: Internet
Author: User

1. Enumeration definition: Use the enum keyword to place their entire definition within a pair of curly braces

Enum Someeumeration

{

Enumeration definition goes here

}

2. Use of enumerations:

Enum Gender

{

Case Male

Case Female

}

Let WW

{

Case. Male:

Print ("Nan Ren")

Case Gender.female:

Print ("NV ren")

}

3. The associated value of the enumeration:

Enum Gender

{

Case Male (String)

Case Femla (int, string)//indicates that any type can be associated, and the data associated with each case can be different

}

Let Wd=gender.male ("male")

Switch WD

{

Case. Male (Let X):

Print ("Zhe shi Yi ge \ (x)")

Case. Female:

Print ("NV ren")

}

Let Hy=gender.female ("Zhang")

Swich WD

{

Case. Male (Let X):

Print ("Zhe shi Yi ge \ (x)")

Case Let. Female (x, y)://equals x and Y are let

Print ("NV ren")

}

4. Native value

Native value, all native values must be unique
Enum Status:int
{
Case Unapproved
Case approved
Case X=5//=1 on the error
Case Y
Case A
}
Let goods=status.approved
Goods.rawvalue

Swift enumeration Code

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.