Skip to content

DynamicMacro v1.0.1-beta

Pre-release
Pre-release

Choose a tag to compare

@TariqAlmazyad TariqAlmazyad released this 06 May 19:21
· 7 commits to main since this release

Thought for a couple of seconds

Release v2.1.1 – Fully Customizable ID Injection

What’s changed?

  • 🔧 Computed & Stored IDs

    • Now you can inject either a computed or stored id of any type—String, Int, Bool, custom model—and the macro will pick the right strategy:

      • Structs & Classes: stored property
      • Enums: computed property
  • 🎯 Optional ID Injection

    • If you provide your own id, the macro does nothing.

    • If you don’t, it injects:

      // Struct / Class:
      public var id: IDType = <defaultInitialization>
      
      // Enum:
      public var id: IDType { <defaultInitialization> }
  • ⚙️ Parameterize Your ID Type

    @Identifiable(idType: String.self)    // String IDs
    @Identifiable(idType: Int.self)       // Int IDs
    @Identifiable(idType: Bool.self)      // Bool IDs
    @Identifiable(idType: MyCustomKey.self) // Your own model
  • 🔄 Default Fallback

    • Omit idType: entirely and you’ll still get a UUID-based id as before.

Example

@Equatable
@Hashable
@Identifiable(idType: String.self)
struct Task {
    var title: String
    var isDone: Bool
}

Expands to:

struct Task {
    var title: String
    var isDone: Bool

    // injected stored ID:
    public var id: String = UUID().uuidString
}

// synthesized conformance
extension Task: Identifiable {}

Upgrade to v2.1.1 for full control over your model IDs—no more boilerplate, just point & inject!