I'm a beginner to Objective-C, coming over from Swift. It seems as if there are two different @interface
instances in which I can declare my ivars. One in my header file, such as this:
// Header file
@interface ViewController : UIViewController
{
// declare instance variables
}
@end
And another that I can add in my implementation file, such as this:
// Implementation file
@interface ViewController ()
// declare instance variables
@end
@implementation ViewController
@end
EDIT: I was learning the "old way" of doing things, which taught me to declare private ivars in the .h file. My confusion stemmed from seeing ivars declared in .h (old way) as well as in .m (new, preferred way). Here's what I've learned (so far...):
// .h
@interface SomeClass : UIViewController
@property (nonatomic, assign) BOOL someBool;
// declare other properties, which will all be public
@end
// .m
@interface SomeClass () <UITextFieldDelegate>
// what do I declare here?...
@end
@implementation SomeClass {
// ...and what do I declare here?
}
// method implementations
@end
However, I'm still confused as to the difference between my .m's @interface
and the @implementation
curly brackets. @matt said to never use curly brackets, but @rmaddy's answer here suggests that @implementation SomeClass {}
is ok. So, which is it?