I am trying to understand the syntax for tuple arrays in Swift:
If I create a tuple:
var gameScore: (points: Int, player: String)
I can assign these values:
gameScore = (1700, "Lisa")
And create an array of this tuple:
var gameScores = [gameScore]
I can add to the array as follows:
gameScores.append((1650, "Bart"))
And thus:
gameScore = (1600, "Maggie")
gameScores += [gameScore]
But not like that:
gameScores += [(1600, "Maggie")]
Playground error:
Playground execution failed: error: Tuples Playground.playground: 38: 1: error: cannot convert value of type '[(points: Int, player: String)]' to the expected argument type 'inout _' gameScores + = [(1600 , "Maggie")]
However, this method works:
gameScores += [(points: 1600, player: "Maggie")]
Yes. I have the code above that will work, but I'm trying to figure out what I don't understand in the failure syntax. Elements should not be named for the method .append(), but they must be named for += [()].