在Objective-C,有一个排序的hackish的方法来创建私有方法,在.m文件:创建在Objective-C专用属性
@interface FooClass (PrivateMethods)
- (void) doBar:(id)barAction withBaz:(id)bazAction;
@end
这个伟大工程的方法。我试图做同样的属性:
@interface BarClass (PrivateMethods)
@property (nonatomic, strong) BazObject *myBaz;
@end
@implementation BarClass
@synthesize myBaz = _myBaz;
[...]
@end
这带来了一个编译警告:房产类别声明“PrivateMethods”不能用在类的实现来实现。我想我的财产转移到一个类别:
@implementation BarClass (PrivateMethods)
@synthesize myBaz = _myBaz;
@end
然后:@synthesize is not allowed in a category's implementation.
答案显然是“跳槽尝试,只是用实例变量”,但我已经被人在苹果告诉他们” (亲自)转移到完全使用属性。他们带来的安全感(比如枪上的安全感,更难拍到脚上)让我所有人都开心起来,所以有什么办法可以做到这一点而不诉诸裸体爱好者?