You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-4Lines changed: 16 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,6 +81,12 @@ struct PersonBuilder {
81
81
publicstructSeasonBuilder {
82
82
publicvar value: Season = .winter
83
83
84
+
publicinit(
85
+
value: Season = .winter
86
+
) {
87
+
self.value= value
88
+
}
89
+
84
90
publicfuncbuild() -> Season {
85
91
return value
86
92
}
@@ -100,9 +106,16 @@ struct AppStateBuilder {
100
106
## Installation
101
107
The library can be installed using Swift Package Manager.
102
108
109
+
110
+
## Features
111
+
- The macro can be applied to `struct`, `enum` and `class` definitions to generate a builder
112
+
- For `struct` definitions without explicit initialisers the macro makes a best guess to derive the memberwise initialiser. Please create a GitHub issue, in case you find any bugs :)
113
+
- For every `init`-parameter a type dependent default value is set (see the below table). For unknown/custom types, the macro will expect another builder to be defined somewhere else
114
+
- E.x. a known type: `var number: Int = 0`
115
+
- E.x. an unknown type: `var value: MyValue = MyValueBuilder().build()`
116
+
- By default the top level access level (e.x. `public`, `private`, etc.) of `struct`, `enum` and `class` definition is also appled to the builder. If you need the builder to have a lower access level you can define it via `@Buildable(accessLevel: .internal)`
117
+
103
118
## Limitations
104
-
- The macro only works on `struct`, `enum` and `class` definitions
105
-
- The list of default values is limited to the values specified in the below table. All other types will require another builder to be defined
106
119
- If a builder for a specific declaration can not be generated, you can always choose to create it yourself by following the below builder naming pattern:
107
120
```swift
108
121
struct <MyType>Builder {
@@ -113,7 +126,6 @@ The library can be installed using Swift Package Manager.
113
126
}
114
127
```
115
128
- If a classor a struct has one or more initialisers, the macro will use the first/top one
116
-
- For structs without an initialiser, the macro makes a best guess to decide how the implicit memberwise initializer could look like. This best guess might fail for declarations that have not been considered during implementation of the macro
117
129
- As of Swift 6.2.0 and Xcode 26.0 (02.10.2025) it is not possible to use the generated builders inside the SwiftUI `#Preview` closure
118
130
119
131
## Builder default values
@@ -158,4 +170,4 @@ assuming that the `UnknownTypeBuilder` was created somewhere else.
158
170
159
171
## Roadmap
160
172
161
-
The `@Buildable` macro was created out of personal interest to reduce repetitive code in my own projects. I might continue developing the macro depending use cases I stumble across, though, I do not guarantee to keep the project up to date myself. Please create GitHub issues forany feature or bugfix you would like to see within the macro. Contributions or fixes from the Community are most welcome.
173
+
The `@Buildable` macro was created out of personal interest to reduce repetitive code in my own projects. I might continue developing the macro depending on use cases I stumble across, though, I do not guarantee to keep the project up to date myself. Please create GitHub issues forany feature or bugfix you would like to see within the macro. Contributions or fixes from the Community are most welcome.
0 commit comments