Skip to content

Add @_UncheckedMemberwiseInit macro (#36) #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2024

Conversation

gohanlon
Copy link
Owner

@gohanlon gohanlon commented Jul 14, 2024

Introduce a new experimental macro for generating memberwise initializers with reduced safety checks compared to @MemberwiseInit.

Features of @_UncheckedMemberwiseInit:

  • Include all properties in the initializer, regardless of access level
  • Include attributed properties by default (differs from @MemberwiseInit)
  • Allow exposure of lower access level members without per-member annotation
  • Has the same usage as @MemberwiseInit

@_UncheckedMemberwiseInit provides a trade-off between ease of use and compile-time safety, suitable for scenarios where brevity is preferred over strict access control enforcement. Note that the underscore prefix indicates this is an experimental feature.

Example:

@_UnsafeMemberwiseInit(.public)
public struct ViewModel {
  private let title: String
}

Yields:

public init(title: String) {
  self.title = title
}

@gohanlon gohanlon force-pushed the unchecked-memberwise-init branch 2 times, most recently from f6fc281 to 8f41219 Compare July 14, 2024 02:33
@gohanlon gohanlon self-assigned this Jul 14, 2024
Introduce a new experimental macro for generating memberwise
initializers with reduced safety checks compared to `@MemberwiseInit`.

Features of `@_UncheckedMemberwiseInit`:
- Include all properties in the initializer, regardless of access level
- Include attributed properties by default (differs from
  `@MemberwiseInit`)
- Allow exposure of lower access level members without per-member
  annotation
- Has the same usage as `@MemberwiseInit`

`@_UncheckedMemberwiseInit` provides a trade-off between ease of use and
compile-time safety, suitable for scenarios where brevity is preferred
over strict access control enforcement. Note that the underscore prefix
indicates this is an experimental feature.

Example:

```swift
@_UnsafeMemberwiseInit(.public)
public struct ViewModel {
  private let title: String
}
```

Yields:

```swift
  public init(title: String) {
    self.title = title
  }
```
@gohanlon gohanlon force-pushed the unchecked-memberwise-init branch from 8f41219 to 90321dc Compare July 15, 2024 21:47
@gohanlon gohanlon merged commit b15e015 into main Jul 15, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant