Arrays of tuples

In Swift 2, I created an array of tuples and try to append an item such as:


var foo = [(Int, String)]()

foo.append((400, "Bad Request"))


I get an error:

error: missing argument for parameter #2 in call foo.append((400, "Bad Request"))


However, if I do:


var foo = [(Int, String)]()

let e = (400, "Bad Request")

foo.append(e)


It compiles.


This code worked with the previous version of XCode and Swift, and the release notes don't make any mention of changes to tuples.


Is this a bug or am I doing something wrong?

This used to happen pre-2 also. Paren stuff. Try:


foo.append((Int, String)(400, "Bad Request"))


or


foo += [(400, "Bad Request")]

Also: foo.append(400, "Bad Request")

Hi Erica, thanks for the reply. In keeping my original post short, I neglected to mention that the way I ran into this is that I opened a project that worked fine with XCode 6.3.2 but that did not compile with XCode 7. So for me, this did not happen with pre-2, or at least not with the current released version of XCode.


Paste the following into a new iOS Playground in both XCode 6.3.2 and 7. It works in the former but not in the latter.


import UIKit
var errors = [(Int, String)]()
errors.append((400, "Bad Request"))


Would like to hear from someone from Apple if this is a bug or a language change.

If the generic type is a tuple, I believe the parentheses are inferred. This works for me in a playground:


import UIKit
var a: Array<(Int, String)> = Array()
var b = [(Int, String)]()
let myElement = (0, "Test zero")
a.append(myElement)
a.append(1, "Test one")
b.append(myElement)
b.append(3, "Test three")
print(a)
print(b)
Arrays of tuples
 
 
Q