Sun*_*day 13 interface objective-c curly-braces
以下代码编译:
@interface MyClass : ParentClass // missing {
// missing }
@property (nonatomic, copy) NSString *myString;
@end
我想知道@interface声明中的花括号是否真的是必要的.
Noa*_*oon 21
不,该{ }部分没有必要; 没有它你的代码将编译正常.它是您声明实例变量的区域,如果您不这样做,您可以自由地将其保留.您实际上甚至不需要为您的属性声明ivars  - 编译器足够聪明,可以在需要的地方添加它们.
编译器足够聪明,可以将@property delarations添加到类中.
这些括号的唯一用途是当您想要将变量设为私有,受保护或特定公开时.
例:
@interface Example: NSObject {
@public
    int publicVar;
@private
    int privateVar;
    int privateVar2;
@protected
    int protectedVar;
}
@end