SWIFT Enumeration (2)

Source: Internet
Author: User

Previously recorded by Swift enumeration (1), this is the continuation of it, continue to say enumeration, see the following definition

Enum Trainstatus {

Case OnTime

Case Delay (INT)//with associated values

}

var mytrainstatus = Trainstatus.delay (10)

Match objects with switch

Switch mytrainstatus{

Case. OnTime:

println ("Train is OnTime")

Case. Delay (Let minutes):

println ("Train delays \ (minutes) minutes")

}

The matching method is sequential, the above first match to delay and then to the inside of the minutes assignment, OK below I will demonstrate interval matching.

Switch mytrainstatus{

Case. ontime://Match on time

println ("Train is OnTime")

Case. Delay (1...5)://Match 1 to 5

println ("Train delays less than five minutes")

Case. Delay (6...10)://Match 6 to 10

println ("Train delays between six and ten minutes")

Case. Delay (_)://Match other, inside is underline

println ("Train delays more than ten minutes")

}

SWIFT Enumeration (2)

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.