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:
You can uncheck the 'Missing Braces and Parentheses' in Build settings (under 'GCC 4.2 Warnings' if you use GCC4.2 or LLVM GCC4.2).
This is equivalent to the answer linked by aeprius, which works with LLVM 2.0, but not with GCC 4.2 (tested).
I understand that this warning is now turned on by default to avoid the confusion between assignment and testing for equality.
As Bavarious noted here, if(self=[super init]){...} is idiomatic in Objective-C. The warning was turned off by default In XCode 3.x and it would appear that migrated projects get the 'new default' automatically; pity to get all these warnings on migrated projects.
At least reverting the warning won't making coding less safe than it used to be in XCode 3.x.
I usually do this.
self = [super init];
if(self) {
}
This way, nothing and no one will ever be confused.
use if(self == [self init]).....since you are using a assignment operator " = " in the place of condition .... if statement checks the condition .... n you are assingng a value out there... use "==" instead of "=" ...
thanx.....
change it to if((self = [super init])) this shows the compiler that it is intentional.
You can either put another set of parens around self = [super init] or you can set self before the conditional and then evaluate as if (self).
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.