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

前端 未结 8 1078
野的像风
野的像风 2021-01-02 17:36

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:

         


        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-02 17:36

    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.

提交回复
热议问题