When and what methods should be declared in the @interface section of a class? As I understand, methods that describe what your class does should be declared in the @interface section, but other "helper" methods should not be declared. Is this a correct understanding from my side?
3 Answers
One way is to declare the instance methods in .h file. And, declare the private methods inside the .m, using a Category.
For example, in MyOwnClass.h file.
@interface MyOwnClass
- (void)aInstanceMethod;
@end
And, inside your MyOwnClass.m file, before the @implementation block,
@interface MyOwnClass (MyPrivateMethods)
- (void)aPrivateMethod;
@end
2 Comments
@implementation block.You usually should add your methods to the .h file when you want an external class to have access to it (public methods).
When they're private (only used internally by the class) just put them in your .m file.
Anyway, it's just a pattern. As Objective-C works with messages, even if you don't set a method in your .h file an external file can access it, but at least your auto-complete won't show it.
Comments
You should declare all your methods in your .h The tip from EmptyStack is nice but it's just a tip. If you don't intend to ship your binary as an SDK, you don't really need it.
Objective-C doesn't have (yet) private methods.