mriddi
mriddi

Reputation: 423

How can i add a tuples value to Swift array?

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?

Upvotes: 6

Views: 933

Answers (2)

karthikPrabhu Alagu
karthikPrabhu Alagu

Reputation: 3401

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

The above code works fine

Upvotes: 4

Mike Manh
Mike Manh

Reputation: 343

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

myArray.append( 1,1 );

Upvotes: 4

Related Questions