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)