SWIFT Tuple pattern and struct pattern

Source: Internet
Author: User

Define a tuple

Let color = (1.0,1.0,1.0,1.0)

Switch color{

Case (0.0,0.5...1.0,let blue,_)://Match the first value is 0.0 the second value is 0.5 to 1.0 the 34th value is arbitrary, and the third value is passed to the blue variable

println ("Blue Is \ (blue)")

Case let (r,g,b,1.0) where r = = g && g = = B://Additional conditions where this one is also the value is equal

println ("Opaque grey \ (r * 100)%")

Default

println ("Unkonw")

}

Ganso is done, then define a struct.

struct Color {

var red:double?

var green:double?

var blue:double?

var alpha:double?

Init (red:double,green:double,blue:double,alpha:double) {

self.red = Red

Self.green = Green

Self.blue = Blue

Self.alpha = Alpha

}

}

var mycolor = Color (Red:10, green:20, blue:60, alpha:1.0)

Switch mycolor{

Case let a where a.red = = && A.blue = = 60:

println ("yes")

Default

println ("Unkonw")

}

SWIFT Tuple pattern and struct pattern

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.