I'm still fairly new to Objective-C but I'd love to learn more about how it should be done.
I'm building a simple cheat sheet that I'd like to print and put on my office wall as a reminder.
Here's what I have so far:
// Headers (.h)
// Shows what's available to other classes
@interface ExampleViewController : UIViewController
// Declare public methods, ivars &
// properties that are synthesized.
@end
// Implementation (.m)
// Defines the content of the class
@interface ExampleViewController ()
// Class extension allowing to declare
// private methods, ivars & properties that are synthesized.
@end
@implementation ExampleViewController
// Private Properties
// Method definitions
@end
One thing I don't understand is why have both @interface and @implementation inside the implementation .m file?
I get that we can declare private stuff but why not simply throw them in @implementation like:
@implementation ExampleViewController
UIView *view; // private property
- (void)...more code
@end
#1 - Why should I ever use @interface from within my implementation .m file?
#2 - For header .h, why should I ever use @class more than #import?
#import actually gets the whole definition and @class tells the compiler that the symbol is a class. So I just don't see why I should ever use @class?
#3 - Otherwise, is there anything I should be adding somewhere in my .h or .m cheat sheet?
That's not a problem-related question but a more wiki-esque question so we everybody can look it up and completely and quickly understand those concepts as they are very hard to grasp for any newcomer.
@implementationblock. Also, unlike your example, ivar declarations in the@implementationsection have to be enclosed in curly braces.