什么.0和.1表示Swift 3.0.1

时间:2017-01-16 18:14:37

标签: swift tuples

你好我想知道.0和.1做了什么,或者意味着在某个点常数y知道它是x和y轴,但是.0和.1做了什么?

let somePoint = (1, 1)
switch somePoint {
case (0, 0):
    print("(0, 0) is at the origin")
case (_, 0):
    print("(\(somePoint.0), 0) is on the x-axis")
case (0, _):
    print("(0, \(somePoint.1)) is on the y-axis")
case (-2...2, -2...2):
    print("(\(somePoint.0), \(somePoint.1)) is inside the box")
default:
    print("(\(somePoint.0), \(somePoint.1)) is outside of the box")
}
// Prints "(1, 1) is inside the box"

1 个答案:

答案 0 :(得分:2)

.0中的somePoint.0正在访问元组somePoint的第一个元素(在索引0处)。 .1正在访问第二个元素(在索引1处)。

正如其他人所指出的那样,first section of the language guide, "The Basics".

涵盖了这一点