在Obj-C中使用哪种技术创建私有方法?

Chi*_*ron -1 cocoa-touch objective-c private-methods

当我想在Objective-C中创建私有方法时,我应该使用什么?
1)众所周知的类别技术.
2)@private指令.
(我正在进行iOS开发).

Lil*_*ard 6

@private适用于ivars,不适用于方法.只需在.m文件的顶部创建一个类扩展,并将私有方法放在那里.它看起来像

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

@implementation MyClass
// implement everything
@end
Run Code Online (Sandbox Code Playgroud)