Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do we put code that was in -dealloc when converting to ARC?

I have a class with this method call within dealloc:

- (void)dealloc {

    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}

Where would I remove myself from the notification center once I convert the class to ARC? Should it go within viewDidUnload? The notification is used to listen for events that come from a modal view controller, so I cannot put this code into viewWillDisappear.

like image 296
Alex Stone Avatar asked May 05 '12 12:05

Alex Stone


1 Answers

The dealloc stays in ARC, it's just that you shouldn't be calling [super dealloc] any longer: the compiler inserts the code for you. And of course all the calls to release cannot be made in dealloc (or anywhere else).

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    // [super dealloc]; <<== Compiler inserts this for you
}
like image 139
Sergey Kalinichenko Avatar answered Sep 28 '22 10:09

Sergey Kalinichenko