Repository navigation
DynamicMacro v1.0.1-beta
Pre-release
Pre-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
idof 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 aUUID-basedidas before.
- Omit
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!