"let currentPoint = (1, 2)" what is this kind of variable? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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?

9th Oct 2016, 10:31 PM
ali
1 Answer
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.
4th Nov 2016, 1:29 PM
Benjamin McKissick Jr.
Benjamin McKissick Jr.   - avatar