Search code examples
objective-cxcodellvmcompiler-warningssuppress-warnings

Suppress property definition warning with LLVM 3.0 on ObjC code


Since Xcode 4.2 comes with LLVM 3.0 we're finally able to use automatic synthesizeation. You can turn it on by adding the following two flags to your Other C Flags in the Apple LLVM compiler 3.0 - Language section:

  • -Xclang
  • -fobjc-default-synthesize-properties

Now you can get rid of your @synthesize boiler plate code if you just want the default settings for your property synthesizeation (I guess we already use automatic reference counting).

When I hit build, the compiler warns me about missing @synthesize etc. statements, like so:

MyController.h:34:43: warning: property 'myProperty' requires method 'myProperty' to be defined - use @synthesize, @dynamic or provide a method implementation [3]
@property (strong, nonatomic) MyClass *myProperty;

I prefer a warning-free build, so the question is: How can I suppress this kind of warnings because obviously they don't make sense anymore.


Solution

  • Are you sure -Xclang is passed to the compiler

    clang -x objective-c -Xclang -fobjc-default-synthesize-properties -c TestClass.m -o TestClass.o 
    

    does not show any warnings while

    clang -x objective-c -fobjc-default-synthesize-properties -c TestClass.m -o TestClass.o
    

    does which is by the way correct since no properties are synthesized

    Here is the TestClass.m I used:

    #import <Foundation/Foundation.h>
    
    @interface TestClass : NSObject
    
    @property (nonatomic, strong) NSObject * test;
    
    @end
    
    @implementation TestClass
    
    @end