I have a GKGameModel
that stores its internal state in an array a
of Card
s and a dictionary b
that maps from Int
s to arrays of Card
s. GameplayKit mandates that I must copy this internal state in setGameModel:
.
The following code is meant to just-copy the array and "deep-copy" the dictionary. FWIK this should be sufficient since Card
s themselves never change.
var a: [Card]
var b: [Int: [Card]]
func setGameModel(gameModel: GKGameModel) {
let otherGameModel = gameModel as! GameModel
a = otherGameModel.a
b = otherGameModel.b.map { (i: Int, cards: [Card]) in (i, cards) }
}
However, this causes the following syntax error in the line that attempt the "deep-copy":
Cannot assign a value of type '[(Int, [Card])]' to a value of type '[Int, [Card]]'.
What am I doing wrong?