How to define private methods … sort of

There is no private or protected methods concept in Objective-C. I think it is related to the architecture of invoking method in Objective-C. Each method is invoked like [self method] style or [self performSelector:@selector(method)]. Internally, Objective-C runtime resolves method implementation by searching method name. This architecture gives flexibility to call method and also allows to have “category” but it is hard to support private method.

Apple still can enhance around this area to bring access control but until that time I think unnamed category is the simplest and easiest way to implement private method like declaration.

ClassA.h file

@interface ClassA {
- (void) publicMethod;

ClassA.m file

@interface ClassA()
- (void) privateMethod;

@implementation ClassA
- (void) publicMethod {

#pragma mark -
#pragma mark Private methods
- (void) privateMethod {

Interesting discussions are going on at

No comments yet.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.