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).
Asked
Active
Viewed 499 times
-1

Chiron
- 20,081
- 17
- 81
- 133
1 Answers
6
@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

Lily Ballard
- 182,031
- 33
- 381
- 347
-
1Exactly 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 Oct 29 '10 at 05:04