Pitch: Property Delegates

You wouldn't need to copy the entire implementation. Remember that property delegates are also ordinary types, and it's okay to use them that way:

@propertyDelegate
struct SynchronizedLazy<Value> {
  var underlyingDelegates: Synchronized<Lazy<Value>>
  // initializer matches Lazy's
  init(initialValue: @escaping @autoclosure () -> Value) {
    underlyingDelegates = Synchronized(initialValue: Lazy(initialValue: initialValue()))
  }
  var value: Value {
    get { return underlyingDelegates.value.value }
    set { underlyingDelegates.value.value = newValue }
  }
}
1 Like