I was looking at some code:
@interface ClassName (Private)
- (float)methodOne:(NSDictionary *)argOne;
- (void)methodTwo:(NSDictionary *)argTwo;
@end
@implementation ClassName
....
The above code is at the top of the ClassName.m file which appears to define additional interface methods for the class as private?
Why do this? what is the point? What else could go where (Private) is? Anyone have docs on this?
Thanks
This is a way of keeping methods that the class uses internally from being exposed to others. It’s part of encapsulation. In Objective-C 2.0 (iOS and Mac OS X 10.5+), it’s more common to use a class extension at the top of the implementation file:
A class extension is really just a special case of a category (which is what you’ve asked about). The primary difference is that for a category, the compiler won’t complain even if your @implementation doesn’t include definitions for the methods declared in the category. For methods in a class extension, your class must implement those methods in its main @implementation block or you’ll get a compiler warning.
You’re better off using a class extension in iOS code or Mac code that targets at least Mac OS X 10.5 Leopard.