Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Private methods are appearing as public methods

I am trying to improve the design of my App by using private methods. Coming from .NET I am a little confused because I am declaring these methods in the .m file but from other files they are still showing up i.e. they are still accessible.

.m file:

@interface NSContentWebServiceController (private)

- (NSString *)flattenHTML:(NSString *)html;
- (NSString *)cleanseStringOfJsonP:(NSString *)jsonP;
- (void)retrieve:(NSasdf *)hasdel :(NSDictionary *)rootList;   
- (NSString *)removeHTMLTagsFromString:(NSString *)aString;

@end
like image 407
TheLearner Avatar asked Feb 27 '23 04:02

TheLearner


1 Answers

As JoostK said, there are no private methods in Objective-C like you have them in C++, Java or C#.

On top of that, the expression @interface NSContentWebServiceController (private) defines a so-called category in Objective-C. The term private here is merely a name for the category and has no meaning. Having something like yellowBunny in here would yield the same effect. A category is merely a way to break down a class into several pieces, but at runtime all categories are in effect. Note that a category is only able to add new methods to an object class, but not new variables.

For private categories it's now preferred to use the anonymous category, as in @interface MyClass(), as you then don't need a separate @implementation MyClass(yellowBunny) block but can just add the methods to main @implementation block.

See the "Categories" section in the Wikipedia entry on Objective-C for more information.

like image 88
DarkDust Avatar answered Mar 12 '23 09:03

DarkDust