10

In a nsobject you have a property "keyPath" you want to observe itself and you use

[self addObserver:self forKeyPath:keyPath options:NSKeyValueObservingOptionNew context:nil];

Does the above line cause a retain cycle?

I present this question because I wanted to know if it was a viable alternative to rewriting a bunch of setter functions.

Yogurt
  • 2,913
  • 2
  • 32
  • 63

1 Answers1

11

From the docs:

Neither the receiver, nor anObserver, are retained.

zadr
  • 2,505
  • 18
  • 19
  • Damn missed that part. "Discussion Neither the receiver, nor anObserver, are retained." – Yogurt Apr 06 '14 at 16:07
  • 1
    Learned my lesson. I made the mistake of only reading the popover text when clicking on the function call and holding option/alt, if I went to the action AppleDocs html I would have seen the discussion text that would have said that. Sorry for the trouble. – Yogurt Apr 07 '14 at 21:36
  • Because Apple doesn't take permalinks seriously, the info is still out there, but has moved here: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/KeyValueObserving/Articles/KVOBasics.html#//apple_ref/doc/uid/20002252-BAJEAIEE Note: The key-value observing addObserver:forKeyPath:options:context: method does not maintain strong references to the observing object, the observed objects, or the context. You should ensure that you maintain strong references to the observing, and observed, objects, and the context as necessary. – nteissler Aug 31 '20 at 20:40