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 496 times
-1
Chiron
- 19,673
- 15
- 77
- 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
- 176,187
- 29
- 372
- 338
-
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