gohanlon / swift-memberwise-init-macro

Swift Macro for enhanced automatic inits.
MIT License
122 stars 8 forks source link

Add `@_UncheckedMemberwiseInit` macro (#36) #40

Closed gohanlon closed 4 months ago

gohanlon commented 4 months ago

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

Features of @_UncheckedMemberwiseInit:

@_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
}