目标C中的私有财产 [英] private property in Objective C
本文介绍了目标C中的私有财产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在目标C中声明私有财产?目的是受益于实现某种内存管理方案但尚未公开的综合获取器和设置器.
Is there a way to declare a private property in Objective C? The goal is to benefit from synthesized getters and setters implementing a certain memory management scheme, yet not exposed to public.
尝试在类别中声明属性会导致错误:
An attempt to declare a property within a category leads to an error:
@interface MyClass : NSObject {
NSArray *_someArray;
}
...
@end
@interface MyClass (private)
@property (nonatomic, retain) NSArray *someArray;
@end
@implementation MyClass (private)
@synthesize someArray = _someArray;
// ^^^ error here: @synthesize not allowed in a category's implementation
@end
@implementation MyClass
...
@end
推荐答案
我实现了这样的私有属性.
I implement my private properties like this.
MyClass.m
MyClass.m
@interface MyClass ()
@property (nonatomic, retain) NSArray *someArray;
@end
@implementation MyClass
@synthesize someArray;
...
这就是您所需要的.
这篇关于目标C中的私有财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文