Skip to content

Commit 1cebd0e

Browse files
committed
Prepare README for 0.5.0 release
- Add quick reference and feature sections about the new `@_UncheckedMemberwiseInit` macro.
1 parent 80a8c81 commit 1cebd0e

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Informed by explicit developer cues, MemberwiseInit can more often automatically
2626
* [Attributed properties are ignored by default, but includable](#attributed-properties-are-ignored-by-default-but-includable)
2727
* [Support for property wrappers](#support-for-property-wrappers)
2828
* [Automatic `@escaping` for closure types (usually)](#automatic-escaping-for-closure-types-usually)
29+
* [Experimental: Unchecked memberwise initialization](#experimental-unchecked-memberwise-initialization)
2930
* [Experimental: Deunderscore parameter names](#experimental-deunderscore-parameter-names)
3031
* [Experimental: Defaulting optionals to nil](#experimental-defaulting-optionals-to-nil)
3132
* [Tuple destructuring in property declarations isn’t supported (yet)](#tuple-destructuring-in-property-declarations-isnt-supported-yet)
@@ -45,7 +46,7 @@ To use MemberwiseInit:
4546

4647
```swift
4748
dependencies: [
48-
.package(url: "https://github.com/gohanlon/swift-memberwise-init-macro", from: "0.4.0")
49+
.package(url: "https://github.com/gohanlon/swift-memberwise-init-macro", from: "0.5.0")
4950
]
5051
```
5152

@@ -176,6 +177,9 @@ Attach to the property declarations of a struct that `@MemberwiseInit` is provid
176177
* `@MemberwiseInit` on `actor`, `class` *(experimental)*
177178
<br> Attachable to actor and class.
178179

180+
* `@_UncheckedMemberwiseInit` *(experimental)*
181+
<br> Generate a memberwise initializer for all properties, regardless of access level, with reduced compile-time safety checks (compared to `@MemberwiseInit`).
182+
179183
## Features and limitations
180184

181185
### Custom `init` parameter labels
@@ -598,6 +602,43 @@ public init(
598602
}
599603
```
600604

605+
### Experimental: Unchecked memberwise initialization
606+
607+
`@_UncheckedMemberwiseInit` is an experimental macro that bypasses compile-time safety checks and strict access control enforcement. It generates an initializer for all properties of a type, regardless of their declared access levels. Use it judiciously.
608+
609+
Key characteristics:
610+
611+
- Generates an initializer that includes all properties, regardless of their declared access levels
612+
- Includes attributed properties by default (differs from `@MemberwiseInit`)
613+
- Follows the same usage pattern as `@MemberwiseInit`
614+
615+
Example:
616+
617+
```swift
618+
@_UncheckedMemberwiseInit(.public)
619+
public struct APIResponse: Codable {
620+
public let id: String
621+
@Monitored internal var statusCode: Int
622+
private var rawResponse: Data
623+
624+
// Computed properties and methods...
625+
}
626+
```
627+
628+
This yields a public initializer that includes all properties, regardless of their access level or attributes. Unlike `@MemberwiseInit`, this macro doesn't require `@Init` annotations or any other explicit opt-ins. The resulting initializer is:
629+
630+
```swift
631+
public init(
632+
id: String,
633+
statusCode: Int,
634+
rawResponse: Data
635+
) {
636+
self.id = id
637+
self.statusCode = statusCode
638+
self.rawResponse = rawResponse
639+
}
640+
```
641+
601642
### Experimental: Deunderscore parameter names
602643

603644
> **Note**

Tests/MemberwiseInitTests/ReadmeTests.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ final class ReadmeTests: XCTestCase {
1111
macros: [
1212
"MemberwiseInit": MemberwiseInitMacro.self,
1313
"Init": InitMacro.self,
14+
"_UncheckedMemberwiseInit": UncheckedMemberwiseInitMacro.self,
1415
]
1516
) {
1617
super.invokeTest()
@@ -526,6 +527,41 @@ final class ReadmeTests: XCTestCase {
526527
}
527528
}
528529

530+
func testUncheckedMemberwiseInit() {
531+
assertMacro {
532+
"""
533+
@_UncheckedMemberwiseInit(.internal)
534+
public struct APIResponse: Codable {
535+
public let id: String
536+
@Monitored internal var statusCode: Int
537+
private var rawResponse: Data
538+
539+
// Computed properties and methods...
540+
}
541+
"""
542+
} expansion: {
543+
"""
544+
public struct APIResponse: Codable {
545+
public let id: String
546+
@Monitored internal var statusCode: Int
547+
private var rawResponse: Data
548+
549+
internal init(
550+
id: String,
551+
statusCode: Int,
552+
rawResponse: Data
553+
) {
554+
self.id = id
555+
self.statusCode = statusCode
556+
self.rawResponse = rawResponse
557+
}
558+
559+
// Computed properties and methods...
560+
}
561+
"""
562+
}
563+
}
564+
529565
func testDeunderscoreParameterNames() {
530566
assertMacro {
531567
"""

0 commit comments

Comments
 (0)