Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is NSNotificationCenter removeObserver in ARC needed? [duplicate]

Does adding an observer increase the retain count of an object? If yes, does ARC handle the removing of this observer too? If not, where should I remove the observer?

like image 858
Tudor Avatar asked Mar 27 '13 10:03

Tudor


Video Answer


1 Answers

You should explicitly remove the observer even you use ARC. Create a dealloc method and remove there..

-(void)dealloc {     [[NSNotificationCenter defaultCenter] removeObserver:self]; } 

If you see the method you don't need to call [super dealloc]; here, only the method without super dealloc needed.

UPDATE for Swift

You can remove observer in deinit method if you are writing code in swift.

deinit {         NSNotificationCenter.defaultCenter().removeObserver(self)        } 
like image 188
nsgulliver Avatar answered Sep 20 '22 02:09

nsgulliver