How to add tuple value to Swift array?

I have an array:

var myArray:[(Int,Int)] = [] 

But when I add value to it:

 myArray.append((1,2)) 

The compiler displays an error warning. What is wrong with my syntax?

+6
source share
2 answers
  var myArray:(Int,Int)[] = [] myArray.append( 1,1 ); print("myArray =\(myArray)"); 

The above code works fine

+4
source

Your tuple does not need a second set of parentheses around it. This works great:

 myArray.append( 1,1 ); 
+4
source

Source: https://habr.com/ru/post/972431/


All Articles