Search code examples
objective-cxcodexcode4

XCode 4 if (self = [super init]) issue


I have recently (e.g. just now) upgraded to XCode 4, and I like it overall, however, there is one thing that annoys me.

When I write code like this:

 if (self = [super init])
 {
      ...
 }

It gives me an 'issue': Using the result of an assignment as a condition without parentheses

How can I suppress this warning, as It underlines all the text in red, making me think that there is a critical error. As I am a somewhat seasoned Objective-C coder, I really don't want to change my practices and add extra parentheses around my init statements.


Solution

  • You can either put an additional set of parentheses in the if statement

    if ((self = [super init])) {
        ...
    }
    

    Or, you can do as the new templates do.

    self = [super init];
    if(self) {
        ...
    }