Created
February 25, 2016 03:06
-
-
Save azinman/4392b087939b1a87d1c8 to your computer and use it in GitHub Desktop.
swift limitations for reflection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum X : Int { | |
case Foo = 2 | |
case Bar = 8 | |
case Baz = 4 | |
} | |
// Can also do this with no difference | |
// enum X { | |
// case Foo | |
// case Bar | |
// case Baz | |
//} | |
X.Foo.dynamicType == X.Bar.dynamicType // true | |
ObjectIdentifier(X.Foo.dynamicType) == ObjectIdentifier(X.Bar.dynamicType) // true | |
// Can't know its Foo | |
let m = Mirror(reflecting: X.Foo) | |
m.description // "Mirror for X" | |
m.children.count // 0 | |
m.subjectType // X.type |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This seems fine, unless I'm misinterpreting. X.Foo is evaluated to 2 and X.Bar is evaluated to 8. At that point they are values and unattached to the data structure that they came from. As far as what we would need for vdl, we would need to identify the labels that are available in X and be able to set/read from them. Does this prevent us from doing that? - It doesn't seem like it but I'm not very knowledgable on how enums work in swift