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

**URL:** <https://forums.swift.org/t/a-macro-that-sets-the-cases-of-an-enum-as-properties-of-a-struct/88988>\
**Category:** Using Swift\
**Tags:** macro\
**Created:** [August 15, 2026, 4:15pm UTC](https://forums.swift.org/t/a-macro-that-sets-the-cases-of-an-enum-as-properties-of-a-struct/88988 "2026-08-15T16:15:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sspringer](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sspringer](https://forums.swift.org/u/sspringer)\
**Post date:** [August 15, 2026, 4:15pm UTC](https://forums.swift.org/t/a-macro-that-sets-the-cases-of-an-enum-as-properties-of-a-struct/88988/1 "2026-08-15T16:15:07Z")

</div>

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

```swift
enum E: CaseIterable {
    case a
    case b
}

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

```

should result in the following declaration of `S`:

```swift
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?

---

<div class="post-metadata">

**Author:** ![MahdiBM](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mahdibm/32/45271_2.png) [@MahdiBM](https://forums.swift.org/u/MahdiBM)\
**Post date:** [August 15, 2026, 5:59pm UTC](https://forums.swift.org/t/a-macro-that-sets-the-cases-of-an-enum-as-properties-of-a-struct/88988/2 "2026-08-15T17:59:11Z")

</div>

See the README examples in [GitHub - MahdiBM/enumerator-macro: A utility for writing boilerplate code for enums · GitHub](https://github.com/MahdiBM/enumerator-macro).

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