I'm writing an Objective-C application using ARC and it's definitely a great improvement even though I never really minded retain counts. However, there's one case I couldn't find in the documentation on first glance.
If, in my init
method, I call [self addObserver:self forKeyPath:…]
to get notifications of when an ivar declared using an @property
directive, do I need to explicitly call removeObserver…
in the dealloc
method, or does ARC handle key value observer cleanup? Similarly if I add my object to a NSNotificationCenter
, does that need to be explicitly removed in dealloc
?
You need to call removeObserver
, ARC only automates retain counts. removeObserver
does not impact the retain count
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With