# Pitch: Property Delegates

**URL:** <https://forums.swift.org/t/pitch-property-delegates/21895>\
**Category:** Pitches\
**Created:** [March 21, 2019, 9:30pm UTC](https://forums.swift.org/t/pitch-property-delegates/21895 "2019-03-21T21:30:09Z")\
**Posts on this page:** 1\
**Showing post:** 152

<div class="post-metadata">

**Author:** ![Srdan\_Rasic](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/srdan_rasic/32/5396_2.png) [@Srdan\_Rasic](https://forums.swift.org/u/Srdan_Rasic)\
**Post date:** [March 25, 2019, 3:14pm UTC](https://forums.swift.org/t/pitch-property-delegates/21895/152 "2019-03-25T15:14:15Z")

</div>

Those are some great thoughts and thinking out of the box. I've been pondering over if this could be related to the ideas from [Key-Path Member Lookup](https://forums.swift.org/t/pitch-key-path-member-lookup/21579). There seems to be some overlap and we should consider if these two proposals could be different sides of a same, yet undefined, abstraction.

It's a really wild idea, but one could implement `Lazy` as a `@keyPathMemberLookup` type:

```
@keyPathMemberLookup
enum Lazy<Value> {
    case uninitialized(() -> Value)
    case initialized(Value)

    init(initialValue: @autoclosure @escaping () -> Value) {
        self = .uninitialized(initialValue)
    }

    var value: Value {
        mutating get {
            switch self {
            case .uninitialized(let initializer):
                let value = initializer()
                self = .initialized(value)
                return value
            case .initialized(let value):
                return value
            }
        }
        set {
            self = .initialized(newValue)
        }
    }

    subscript<U>(keyPathMember keyPath: WritableKeyPath<T, U>) -> U {...}
}

```

In which case the declaration would be as simple as

```
var name: Lazy<String>

```

while still getting the underlying type API through the property.

```
name.isEmpty

```

The limitation of `@keyPathMemberLookup` is that it does not support methods in the current proposal, but one would expect that to be possible in future.

There is also a question on how to do the memberwise initializer and if the `value` should be exposed, but those seem to be solvable problems.

---

_[View the full topic](https://forums.swift.org/t/pitch-property-delegates/21895)._
