AssociatedValues icon indicating copy to clipboard operation
AssociatedValues copied to clipboard

How does `key` pointer address remain the same between get/set calls?

Open suparngp opened this issue 5 years ago • 0 comments

A noob question may be.

Following up on your example:

var identifier: String {
      get {
          return getAssociatedValue(key: "identifier", object: self, initialValue: "Unknown")
      }
      set {
          set(associatedValue: newValue, key: "identifier", object: self)
      }
  }

"identifier" in both get and set should have different memory addresses since they are two different objects. So how is it able to retrieve the previously stored value?

suparngp avatar Mar 19 '19 09:03 suparngp