使用LLVM 3.0在ObjC代码上抑制属性定义警告
问题描述:
由于Xcode 4.2随附LLVM 3.0,我们终于可以使用自动合成。您可以通过在Apple LLVM compiler 3.0 - Language
部分添加以下两个标志到Other C Flags
打开它:使用LLVM 3.0在ObjC代码上抑制属性定义警告
-Xclang
-fobjc-default-synthesize-properties
现在你可以,如果你摆脱你的@synthesize
锅炉板代码只是想要你的财产综合的默认设置(我想我们已经使用自动引用计数)。
当我击筑,编译器会警告我错过@synthesize
等语句,就像这样:
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;
我更喜欢无警告的构建,所以问题是:我怎样才能抑制这种警告,因为显然他们没有意义了。
答
确定-Xclang被传递到编译器
clang -x objective-c -Xclang -fobjc-default-synthesize-properties -c TestClass.m -o TestClass.o
不显示任何警告而
clang -x objective-c -fobjc-default-synthesize-properties -c TestClass.m -o TestClass.o
确实是的方式正确的,因为没有任何属性合成
这里是我使用的TestClass.m:
#import <Foundation/Foundation.h>
@interface TestClass : NSObject
@property (nonatomic, strong) NSObject * test;
@end
@implementation TestClass
@end
答
好吧,我设法用这些C标记,以抑制警告:
-Xclang -fobjc-default-synthesize-properties -Wno-objc-property-implementation
不幸的是,getter/setter方法没有得到合成(......而事实上我的应用程序崩溃...)
你让我走向正确的方向。当我用'xcodebuild'从CLI构建时,没有'-Xclang -fobjc-default-synthesize-properties'。我将这些标记添加到项目中,当我将它们移动到目标时,它们显示在构建日志中。我不能说这是为什么,但现在它至少起作用。 –