Skip to content

Commit 63af2b0

Browse files
committed
Update Readme
1 parent c0584cc commit 63af2b0

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ struct PersonBuilder {
8181
public struct SeasonBuilder {
8282
public var value: Season = .winter
8383

84+
public init(
85+
value: Season = .winter
86+
) {
87+
self.value = value
88+
}
89+
8490
public func build() -> Season {
8591
return value
8692
}
@@ -100,9 +106,16 @@ struct AppStateBuilder {
100106
## Installation
101107
The library can be installed using Swift Package Manager.
102108

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+
103118
## 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
106119
- 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:
107120
```swift
108121
struct <MyType>Builder {
@@ -113,7 +126,6 @@ The library can be installed using Swift Package Manager.
113126
}
114127
```
115128
- If a class or 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
117129
- 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
118130

119131
## Builder default values
@@ -158,4 +170,4 @@ assuming that the `UnknownTypeBuilder` was created somewhere else.
158170

159171
## Roadmap
160172

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 for any 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 for any feature or bugfix you would like to see within the macro. Contributions or fixes from the Community are most welcome.

Sources/Buildable/Buildable.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@
5151
/// public struct SeasonBuilder {
5252
/// public var value: Season = .winter
5353
///
54+
/// public init(
55+
/// value: Season = .winter
56+
/// ) {
57+
/// self.value = value
58+
/// }
59+
///
5460
/// public func build() -> Season {
5561
/// return value
5662
/// }

0 commit comments

Comments
 (0)