cfi*_*her 7 cocoa objective-c private-methods objective-c-category
我正在创建一个超过NSDate的类别.它有一些实用方法,不应该是公共接口的一部分.
我怎样才能让它们变成私密的?
在类中创建私有方法时,我倾向于使用"匿名类别"技巧:
@interface Foo()
@property(readwrite, copy) NSString *bar;
- (void) superSecretInternalSaucing;
@end
@implementation Foo
@synthesize bar;
.... must implement the two methods or compiler will warn ....
@end
Run Code Online (Sandbox Code Playgroud)
但它似乎不适用于另一个类别:
@interface NSDate_Comparing() // This won't work at all
@end
@implementation NSDate (NSDate_Comparing)
@end
Run Code Online (Sandbox Code Playgroud)
在类别中使用私有方法的最佳方法是什么?
应该是这样的:
@interface NSDate ()
@end
@implementation NSDate (NSDate_Comparing)
@end
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3860 次 |
最近记录: |