gohanlon / swift-memberwise-init-macro

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

Add `@Init(assignee:type:)` to (awkwardly) support property wrappers #11

Closed gohanlon closed 1 year ago

gohanlon commented 1 year ago

MemberwiseInit can be made to support property wrappers like SwiftUI's @Binding with the addition of two new arguments:

import SwiftUI

@MemberwiseInit
struct CounterView: View {
  @Init(assignee: "self._count", type: Binding<Int>)
  @Binding var count: Int
}

With that, MemberwiseInit can provide the expected initializer for a @Binding-wrapped property:

internal init(
  property: Binding<Int>
) {
  self._count = count
}

This expressiveness may also support the use of other framework-vended property wrappers, custom property wrappers and macros.