Skip to content

Instantly share code, notes, and snippets.

@azinman
Created February 25, 2016 03:06
Show Gist options
  • Save azinman/4392b087939b1a87d1c8 to your computer and use it in GitHub Desktop.
Save azinman/4392b087939b1a87d1c8 to your computer and use it in GitHub Desktop.
swift limitations for reflection
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
@bprosnitz
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment