Swift (2) Ganso (Tuple)

Source: Internet
Author: User


let somePoint = (1, 1)

switch somePoint {
case (0, 0): // at far point
     println ("(0, 0) is at the origin")
case (_, 0): // x is an arbitrary value, y is 0, that is, on the X axis
     println ("(\ (somePoint.0), 0) is on the x-axis")
case (0, _): // y is any value, x is 0, that is, on the Y axis
     println ("(0, \ (somePoint.1)) is on the y-axis")
case (-2 ... 2, -2 ... 2): // in a square centered at the origin and 4 sides long.
     println ("(\ (somePoint.0), \ (somePoint.1)) is inside the box")
default:
     println ("(\ (somePoint.0), \ (somePoint.1)) is outside of the box")
}


tuples are composite values that combine multiple values. The values in a tuple can be any type, and each element can be of a different type .






1) The given tuple element is named, and then the value (tuple. Name) is obtained by name.


 
let http200Status = (statusCode: 200, description: "OK")  
println("The status code is \(http200Status.statusCode)")  
println("The status message is \(http200Status.description)")


Results: 200



Ok



2) obtained by subscript, starting from 0


let http404Error = (404, "Not Found")
// Get the second value by tuple .0
println ("The status code is \ (http404Error.0)")
// Get the second value through tuple.1
println ("The status message is \ (http404Error.1)") 


Reference: http://blog.csdn.net/woaifen3344/article/details/29357261



Tomorrow's plan--look at functions and closures






Swift (2) Ganso (Tuple)


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.