0
"let currentPoint = (1, 2)" what is this kind of variable?
What is the output of the following code? let currentPoint = (1, 2) switch currentPoint { case let (x, y) where x > y: print("(A") case let (x, y) where x == y: print(“B") case let (x, y): print(“C") } This code from the practice in Sololearn Swift. I kinda see something odd to me which pass two values which seems to be separated in one variable, is that right? if yes, why did they represent the first to be x and the second to be y?
1 ответ
0
This is a Tuple. It allows a variable, or constant in this case, to hold two values. They used x and y because they're common placeholder names for integer variables. Just think back to Algebra and Geometry when having to find the value of x or x and y coordinates.