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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With