I just don’t understand why some guys declare the methods in the .m file. Can’t those declarations just go in the .h file instead?? Here’s what I see mostly:
//myClass.h
#import <UIKit/UIKit.h>
@interface myClass: UIViewController
{
}
@end
And the implementation (.m) part:
//myClass.m
#import "myClass.h"
@interface myClass
//declare some methods here
@end
@implementation myClass
//the actual implementation
@end
Is there any difference when the methods are declared this way?? Also, “@private” methods can be declared in myClass.h itself, can’t they?
The code you have posted both doesn’t compile and isn’t equivalent to declaring methods in the header.
The purpose of the header is to provide a set of declarations that other classes can import. They can’t import your implementation file, because that will create duplicate definitions.
As bbum said, what you’re probably seeing is private method declarations in the implementation file. These aren’t intended to be used outside the class, so they’re declared in the implementation file. The feature is called a class extension:
And no, you can’t declare “
@privatemethods” in the header, or anywhere else. There’s no such thing in Objective-C. The@privateaccess specifier only applies to variables.