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).
views:
28answers:
1
+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
2010-10-29 02:19:36
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
2010-10-29 05:04:54