Nested enum as dictionary key
Is there any reason why this doesn't work? Note: enumeration as a dictionary key works if it is not nested.
struct OuterStruct
{
enum InnerEnum
{
case none
case a
case b
}
}
var dict : [OuterStruct.InnerEnum: String] = [OuterStruct.InnerEnum: String]()
+3
user965972
source
to share
1 answer
You can fix this using the traditional way of creating a dictionary:
var dict : [OuterStruct.InnerEnum: String] = Dictionary<OuterStruct.InnerEnum, String>()
Note that you can use type inference and not specify the type of the variable:
var dict = Dictionary<OuterStruct.InnerEnum, String>()
As for why the shorthand syntax doesn't work, I don't have an answer - I think you should file a radar about it. I tried to convert InnerEnum
to struct and class and the same error is reported.
+4
Antonio
source
to share