I defined Dictionary in Swift, with enum as the key and struct as value. At runtime I want to add value to the dictionary for a given enum key, however I get the following error:
'@lvalue $T9' is not identical to '(MyEnum, MyData)'
enum MyEnum {
case A, B, C
}
struct MyData {
var x : Int
var y : Int
init(x:Int, y: Int) {
self.x = x
self.y = y
}
}
class Tester {
let myDictionary = [MyEnum : MyData]()
func dummy() {
self.myDictionary[MyEnum.A] = MyData(x: 1, y: 2) // <-- error in this line
}
}
Any idea how to do it properly ?