MyClass.h ファイル
#import <Foundation/Foundation.h>
@interface MyClass : NSObject
{
// This is the Place of Instance Variable
}
- (void)thePublicMethod;
@end
MyClass.m ファイル
#import "MyClass.h"
@interface MyClass()
- (void)thePrivateMethod;
@end
@implementation MyClass
-(void)thePublicMethod {
NSLog(@"Public Method Called");
}
- (void)thePrivateMethod {
NSLog(@"Private Method Called");
}
@end
main.m ファイル
#import <Foundation/Foundation.h>
#import "MyClass.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
MyClass *myObj = [[MyClass alloc] init];
[myObj thePublicMethod];
// [myObj thePrivateMethod];
}
return 0;
}
「プライベート」メソッドは、クラスの実装ファイルで定義することで作成でき、インターフェイス ファイルからは省略することができます。 main.m から thePrivateMethod にアクセスしたいのですが、thePublicMethod() から thePrivateMethod() を呼び出すこともできますか?