I thought tuples are equivalent if types are the same regardless of label names?
enum Choice: CaseIterable {
case a, b, c, d, e, f
}
let bitMap = Dictionary<Choice, Int>(uniqueKeysWithValues: Choice.allCases.enumerated().map {
(key: $1, value: 1 << $0) // error: Initializer 'init(uniqueKeysWithValues:)' requires the types '(key: Choice, value: Int)' and '(Choice, Int)' be equivalent
// ($1, 1 << $0) // this works
})
This is why I'm confused, no type mismatch compile error when the second element is not bit shift for the same mismatched labeled tuple:
enum Choice: CaseIterable {
case a, b, c, d, e, f
}
let bitMap = Dictionary<Choice, Int>(uniqueKeysWithValues: Choice.allCases.enumerated().map {
// (key: $1, value: 1 << $0) // error: Initializer 'init(uniqueKeysWithValues:)' requires the types '(key: Choice, value: Int)' and '(Choice, Int)' be equivalent
// (key: $1, value: $0) // 👈 !!! exact same tuple as above, now no problem!
(truck: $1, you: $0) // no matter what the labels are, all no problem!
// ($1, 1 << $0) // this works
})
Seems like the bit shift one produce compile error, others fine