1
我有以下代碼:如何使用枚舉(在結構中定義)作爲字典的關鍵?
struct TestStruct2 {
let field1: String
let field2: Int
enum TestEnum2 {
case Value1
case Value2
}
}
let dic2 = Dictionary<TestStruct2.TestEnum2, TestStruct2>()
let dic3 = [TestStruct2.TestEnum2 : TestStruct2]()
DIC2成功的作品。
但dic3返回一個編譯器錯誤:
(Type of expression is ambiguous without more context)
我不明白爲什麼。有任何想法嗎?
這是編譯器故障,見[爲什麼不能實例化一個嵌套類的空數組? ](http://stackoverflow.com/questions/25682113/why-cant-i-instantiate-an-empty-array-of-a-nested-class)你也可以使用嵌套類型的'typealias'來工作周圍。 – Hamish