你好我想知道.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"
答案 0 :(得分:2)
.0
中的somePoint.0
正在访问元组somePoint
的第一个元素(在索引0处)。 .1
正在访问第二个元素(在索引1处)。
正如其他人所指出的那样,first section of the language guide, "The Basics".
涵盖了这一点