views:

28

answers:

1

When I want to create private methods in Objective-C, what should I use?
1) The well known categories technique.
2) @private directive.
(I'm doing iOS development).

+6  A: 

@private is for ivars, not for methods. Just create a class extension at the top of your .m file and put the private methods there. It looks something like

@interface MyClass () // note the empty parens
- (void)onePrivateMethod;
- (void)twoPrivateMethod;
@end

@implementation MyClass
// implement everything
@end
Kevin Ballard
Exactly right save for adding that "there are no truly private methods in Objective-C". More details here: http://stackoverflow.com/questions/2158660/why-doesnt-objective-c-support-private-methods
bbum