# Unexpected behavior with property wrappers and willSet/didSet

**URL:** <https://forums.swift.org/t/unexpected-behavior-with-property-wrappers-and-willset-didset/76887>\
**Category:** Using Swift\
**Created:** [December 27, 2024, 10:06pm UTC](https://forums.swift.org/t/unexpected-behavior-with-property-wrappers-and-willset-didset/76887 "2024-12-27T22:06:32Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jamieQ](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jamieq/32/5117_2.png) [@jamieQ](https://forums.swift.org/u/jamieQ)\
**Post date:** [December 30, 2024, 8:40pm UTC](https://forums.swift.org/t/unexpected-behavior-with-property-wrappers-and-willset-didset/76887/2 "2024-12-30T20:40:58Z")

</div>

this is an interesting question... the supported/intended interactions between property wrappers and observing accessors do appear to be rather vague to me. the example from the evolution document gives the following description of how the wrapper 'expansion' works:

```swift
@Lazy var foo = 1738

// translates to

private var _foo: Lazy<Int> = Lazy<Int>(wrappedValue: 1738)
var foo: Int {
  get { return _foo.wrappedValue }
  set { _foo.wrappedValue = newValue }
}

```

but the fact that you can include an observing accessor on the wrapped property declaration means that the use of a property wrapper enables functionality that cannot be re-created by simply 'desugaring' the wrapper annotation itself. e.g. if we explicitly use the codegen pattern that the wrapper expansion is said to provide on the given example, it is rejected:

```swift
var _value: Wrap<Int> = Wrap<Int>(wrappedValue: 0)
var value: Int {
  get { _value.wrappedValue }
  set { _value.wrappedValue = newValue }
  didSet { print("didSet") } // 🛑 'didSet' cannot be provided together with a getter
}

```

so it seems that in this manner, 'wrapped properties' are something of a hybrid between computed properties, which don't admit observing accessors, and stored properties, which do. if we think of these as essentially just slightly-special computed properties, then the current behavior/limitations perhaps makes more sense, but i can see arguments in both directions.

cc @John_McCall – since [accessors](https://forums.swift.org/t/prospective-vision-accessors/76707) have presumably been on your mind recently, do you have any insights to share on this matter?

---

_[View the full topic](https://forums.swift.org/t/unexpected-behavior-with-property-wrappers-and-willset-didset/76887)._
