Use property-wrapper in closure’s arguments

Updated
Jun 10, 2022 5:21 AM
Created
Jun 10, 2022 5:20 AM
Tags
Swift
Attributes

@propertyWrapper
struct Wrapper<T> {
  
  var wrappedValue: T
  
  var projectedValue: Wrapper<T> { self }
  
  init(wrappedValue: T) {
    self.wrappedValue = wrappedValue
  }
  
  init(projectedValue: Wrapper<T>) {
    self = projectedValue
  }
}

func run<T>(_ value: T, perform: (Wrapper<T>) -> Void) {
  perform(Wrapper.init(wrappedValue: value))
}

run(10) { $value in
  print(value)
}