Skip to content

Commit a536a4f

Browse files
committed
Prepare README for 0.4.0 release
- Add `ReadmeTests.swift` to validate and documentation examples and track changes to their behavior. - Clarified the usage of `_optionalsDefaultNil` to emphasize appropriate scenarios, removing outdated statement about default values being unsupported.
1 parent 334d6d2 commit a536a4f

File tree

2 files changed

+763
-3
lines changed

2 files changed

+763
-3
lines changed

README.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ To use MemberwiseInit:
4545

4646
```swift
4747
dependencies: [
48-
.package(url: "https://github.com/gohanlon/swift-memberwise-init-macro", from: "0.3.0")
48+
.package(url: "https://github.com/gohanlon/swift-memberwise-init-macro", from: "0.4.0")
4949
]
5050
```
5151

@@ -65,6 +65,9 @@ To use MemberwiseInit:
6565
private var age: Int? = nil
6666
//┬──────
6767
//╰─ 🛑 @MemberwiseInit(.public) would leak access to 'private' property
68+
// ✏️ Add '@Init(.public)'
69+
// ✏️ Replace 'private' access with 'public'
70+
// ✏️ Add '@Init(.ignore)'
6871
}
6972
```
7073

@@ -229,6 +232,7 @@ Customize your initializer parameter labels with `@Init(label: String)`:
229232
Explicit type annotations are not required when properties are initialized with an expression whose syntax implies type information, e.g., most Swift literals:
230233

231234
```swift
235+
@MemberwiseInit
232236
struct Example {
233237
var count = 0 // 👈 `Int` is inferred
234238
}
@@ -661,7 +665,7 @@ The default behavior of MemberwiseInit regarding optional properties aligns with
661665
* `let` optional properties are never automatically defaulted to `nil`. Setting `_optionalsDefaultNil` to `true` is the only way to cause them to default to `nil`.
662666

663667
> **Note**
664-
> Use `@Init(default:)` to generally specify default values — it’s a safer, more explicit alternative to `_optionalsDefaultNil`.
668+
> Use [`@Init(default:)`](#default-values-even-for-let-properties) to generally specify default values — it’s a safer, more explicit alternative to `_optionalsDefaultNil`.
665669
666670
#### Explanation
667671

@@ -703,7 +707,7 @@ public struct User {
703707
}
704708
```
705709

706-
While MemberwiseInit doesn’t (yet) solve for default values of `let` properties, `_optionalsDefaultNil` serves the specific case of defaulting optional properties to `nil`:
710+
Where appriopriate, `_optionalsDefaultNil` can be a convenient way to default optional properties to `nil` in the generated initializer:
707711

708712
```swift
709713
@MemberwiseInit(.public, _optionalsDefaultNil: true)
@@ -819,6 +823,10 @@ public struct Person {
819823
private var age: Int?
820824
//┬──────
821825
//╰─ 🛑 @MemberwiseInit(.public) would leak access to 'private' property
826+
// ✏️ Add '@Init(.public)'
827+
// ✏️ Replace 'private' access with 'public'
828+
// ✏️ Add '@Init(.ignore)' and an initializer
829+
}
822830
```
823831

824832
> **Note**

0 commit comments

Comments
 (0)