你好,我想知道.0和.1做了什麼,或者說在某個點常量y知道它是x和y軸,但是什麼是。 0和.1做什麼?.0和.1是什麼意思Swift 3.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"
我會極力推薦閱讀[元組部分(https://developer.apple.com/library/content/documentation/Swift/Conceptual/ Swift_Programming_Language/TheBasics.html#// apple_ref/doc/uid/TP40014097-CH5-ID329)。 – Hamish
您正在聲明一個(Int,Int)元組。它本質上與x或y沒有任何關係,比如調用let somePoint = CGPoint(x:1.0,y:1.0)。所以.0意味着元組的第一個或第零個元素,而.1意味着第二個元素。 –
從語言指南:*或者,使用從零開始的索引號訪問元組中的單個元素值* – Keiwan