Matrosov Alexander Matrosov Alexander - 21 days ago 6
iOS Question

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.

Answer

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. ;)

Comments