Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to get the enum case values/payloads? #108

Open
blacktop opened this issue Sep 12, 2022 · 1 comment
Open

Is it possible to get the enum case values/payloads? #108

blacktop opened this issue Sep 12, 2022 · 1 comment

Comments

@blacktop
Copy link

blacktop commented Sep 12, 2022

enum MyEnum: String {
    case A = "test"
    case B
    case C
}

struct Name {
    var a: MyEnum
    var b: MyEnum
}

Name(a: .A, b: .B)
let info = try! typeInfo(of: MyEnum.self)
print(info)

TypeInfo(kind: Runtime.Kind.enum, name: "MyEnum", type: SwiftDump.MyEnum, mangledName: "MyEnum", properties: [], inheritance: [], size: 1, alignment: 1, stride: 1, cases: [Runtime.Case(name: "A", payloadType: nil), Runtime.Case(name: "B", payloadType: nil), Runtime.Case(name: "C", payloadType: nil)], numberOfEnumCases: 3, numberOfPayloadEnumCases: 0, genericTypes: [])

This is probably just a misunderstanding of mine, but I thought the payload for the A case would be "test"?

@blacktop
Copy link
Author

Also is it possible to get the struct funcs via reflection in this example?

struct E<T> {
  var x : Int
  func foo() { bar() }
  func bar() {}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant