The following code compiles:
@interface MyClass : ParentClass // missing {
// missing }
@property (nonatomic, copy) NSString *myString;
@end
I'm wondering if the curly braces in @interface
declarations are actually necessary.
The following code compiles:
@interface MyClass : ParentClass // missing {
// missing }
@property (nonatomic, copy) NSString *myString;
@end
I'm wondering if the curly braces in @interface
declarations are actually necessary.
No, the { }
section isn’t necessary; your code will compile fine without it. It’s the area where you declare instance variables, and if you’re not doing that, you’re free to leave it out. You don’t even actually need to declare ivars for your properties—the compiler’s smart enough to add them where they’re needed.
The compiler is clever enough to add your @property delarations to the class.
The only use for those brackets is when you want to make a variable private, protected or specifically public.
Example:
@interface Example: NSObject {
@public
int publicVar;
@private
int privateVar;
int privateVar2;
@protected
int protectedVar;
}
@end