6

I have the array:

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

But when I add value to it by:

myArray.append((1,2))

The compiler show mistake warning. What is wrong with my syntax?

1
  • 1
    possible duplicate of Array of tuples in Swift - In short: myArray.append(1,2) works (don't know if this is intended or a Swift bug). myArray += (1,2) works as well. Commented Jul 18, 2014 at 5:16

2 Answers 2

4
    var myArray:(Int,Int)[] = []
    myArray.append( 1,1 );
    print("myArray =\(myArray)");

The above code works fine

Sign up to request clarification or add additional context in comments.

1 Comment

Note that the above example uses pre-beta 3 syntax for array types. The correct syntax now is to place parentheses around the value type, not after them.
4

Your tuple doesn't need a second set of parentheses around it. This works fine:

myArray.append( 1,1 );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.