Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Missing [super dealloc]" warning in an ARC project

I've refactored a project to ARC. It looks fine, but there is an object which uses the notification center. I removed the observer in a custom dealloc method. That worked fine in the non ARC project. It also works in ARC, but I get a crazy warning: "Method possibly missing a [super dealloc] call." In an ARC project it is automatically done for me, when the method ends. Even better: I must not call it in ARC projects! This must be an XCode bug, right? Here's my code:

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    // [super dealloc]; will be called automatically
}

I always want to write code that doesn't throw warnings. Is there a way around that yellow exclamation mark?

like image 515
Ingo Dellwig Avatar asked Aug 28 '12 09:08

Ingo Dellwig


2 Answers

Put the following lines into your dealloc method to make sure it is compiled with ARC enabled:

#if ! __has_feature(objc_arc)
#error "ARC is off"
#endif

If you get the compiler error when building, you're sure that ARC is off and have to search for the reason. It's probably in per-file build settings in your target.

like image 164
Nikolai Ruhe Avatar answered Nov 16 '22 07:11

Nikolai Ruhe


I did resolved this warning by following steps:

  1. Click target(<yourapp>.xcodeproj) in which the file(<classname>.m) class shows above warning
  2. Select TARGET >> Build Phases >> Compile sources
  3. Search file
  4. Add Compiler Flags -fobjc-arc

This is looks like below

enter image description here

like image 33
Kampai Avatar answered Nov 16 '22 07:11

Kampai