A macro that sets the cases of an enum as properties of a struct?

I am struggling to write a macro that does the following:

enum E: CaseIterable {
    case a
    case b
}

@CasesAsProperties(from: E.Type, typeDeclaration: "String")
struct S {
}

should result in the following declaration of S:

struct S {
    let a: String
    let b: String
}

Does there exist a macro like that (could not find one), or else how would such a macro look like?

1 Like

See the README examples in GitHub - MahdiBM/enumerator-macro: A utility for writing boilerplate code for enums · GitHub.

You need to attach the macro to the enum so it has access to the enum's contents.

2 Likes