由于 Xcode 4.2 附带了 LLVM 3.0,我们终于能够使用自动合成。您可以通过将以下两个标志添加到 Apple LLVM compiler 3.0 - Language
部分的 Other C Flags
来打开它:
-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
关于objective-c - 在 ObjC 代码上使用 LLVM 3.0 抑制属性定义警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7892159/