Oleksandr Matrosov
Oleksandr Matrosov

Reputation: 27113

Provide access to the private method that are defined in base class

I have found this explanation, but I think I am a little confused.

So as I understood if I use category in my BaseDataHandler.m:

@interface STDataHandler (STDataHandlerPrivateMethods)

- (void)syncDataWithServer:(NSDictionary *)params;

@end

the method syncDataWithServer will not be found in the child for example DataHandlerPlayer.m.

So my question is how I can provide this method for the child but hide for other classes. If I put this method to @interface in BaseDataHandler.h it will be a public one.

Upvotes: 0

Views: 51

Answers (2)

Hermann Klecker
Hermann Klecker

Reputation: 14068

You cannot do that. Objective-C does not separate between private and protected as Java does.

Upvotes: 0

Nicholas Hart
Nicholas Hart

Reputation: 1724

Take that category definition for your interface and put it in a file called STDataHandler_private.h. Then import STDataHandler_private.h in your child class's .m file.

In theory some other class could import your "private" header and access that method too... so don't do that. ;)

Upvotes: 2

Related Questions