#32: Generic Parameters
Question
// Swift Quiz
— objc.io (@objcio) October 2, 2019
enum LangCode: String, Hashable {
case en, de
}
struct Language<T: RawRepresentable, Hashable> where T.RawValue == String {
var lang: [T: String] = [.de: "D"]
}
let a = Language<LangCode, String>(lang: [.en: "E"])
// What’s the value of a.lang?
Solution
Solution: Compiler Error
— objc.io (@objcio) October 3, 2019
Type T does not conform to protocol Hashable.
The way we define our Language struct, Hashable is a generic parameter, not a constraint on T.
See also: https://t.co/YRMEaGYEcR
Thanks to @olebegemann for pointing this out.https://t.co/s7500CWmAg