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
- 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.
//╰─ 🛑 @MemberwiseInit(.public) would leak access to 'private' property
68
+
// ✏️ Add '@Init(.public)'
69
+
// ✏️ Replace 'private' access with 'public'
70
+
// ✏️ Add '@Init(.ignore)'
68
71
}
69
72
```
70
73
@@ -229,6 +232,7 @@ Customize your initializer parameter labels with `@Init(label: String)`:
229
232
Explicit type annotations are not required when properties are initialized with an expression whose syntax implies type information, e.g., most Swift literals:
230
233
231
234
```swift
235
+
@MemberwiseInit
232
236
structExample {
233
237
var count =0// 👈 `Int` is inferred
234
238
}
@@ -661,7 +665,7 @@ The default behavior of MemberwiseInit regarding optional properties aligns with
661
665
*`let` optional properties are never automatically defaulted to `nil`. Setting `_optionalsDefaultNil` to `true` is the only way to cause them to default to `nil`.
662
666
663
667
> **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`.
665
669
666
670
#### Explanation
667
671
@@ -703,7 +707,7 @@ public struct User {
703
707
}
704
708
```
705
709
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:
0 commit comments