Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 542
Richard J. Ross III Avatar asked Mar 17 '11 20:03

Richard J. Ross III


2 Answers

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) {
    ...
}
like image 200
Grant Limberg Avatar answered Nov 12 '22 18:11

Grant Limberg


I found the answer to this question here: if(self = [super init]) - LLVM warning! How are you dealing with it?

Which prescribes adding the "-Wno-idiomatic-parentheses" flag in the building settings. Which did the trick for me.

like image 25
aepryus Avatar answered Nov 12 '22 18:11

aepryus