Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i add a tuples value to Swift array?

Tags:

arrays

swift

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?

like image 531
mriddi Avatar asked Jul 18 '14 05:07

mriddi


People also ask

Is tuple value type in Swift?

Types in Swift fall into one of two categories: first, “value types”, where each instance keeps a unique copy of its data, usually defined as a struct, enum, or tuple. The second, “reference types”, where instances share a single copy of the data, and the type is usually defined as a class.


1 Answers

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

The above code works fine

like image 108
karthikPrabhu Alagu Avatar answered Nov 11 '22 03:11

karthikPrabhu Alagu