Just assign the tuple to a temp variable:
let tuple = (
id: idInt,
name: nameString
)
arrayObj.append(tuple)
Not sure why it doesn't work that way - just checked on a function, like this:
var array: [(param1: Int, param2: String)] = []
func test(x: (param1: Int, param2: String)) {
println(x)
}
test((param1: 2, param2: "Test"))
array.append((param1: 2, param2: "Test"))
Result: the function works, the array method doesn't.
Update: Tried this code in a playground:
struct Test<T> {
func doSomething(param: T) {
println(param)
}
}
var test = Test<(param1: Int, param2: String)>()
let tuple = (param1: 2, param2: "Test")
test.doSomething(tuple)
test.doSomething((param1: 2, param2: "Test"))
Result: it works when passing the tuple
variable to doSomething
- using the literal tuple instead doesn't, although the compiler message is different:
'((param1: Int, param2: String)) ->()' does not have a member named 'doSomething'
Apparently passing a literal tuple to a method of a generic class (where the tuple is the generic type) is not correctly handled by the compiler.
Update #2: I repeated the test on a non-generic class, but using a generic method, and in this case it worked:
struct Test {
func doSomething<T>(param: T) {
println(param)
}
}
var test = Test()
let tuple = (param1: 2, param2: "Test")
test.doSomething(tuple)
test.doSomething((param1: 2, param2: "Test"))
So it's definitely a problem related to generic classes only.