公开api readonly,但内部读/写?

时间:2012-09-14 01:38:15

标签: objective-c

我该怎么做:

@interface Foo : NSObject
@property (readonly) int bar;
@end

...

@interface Foo()
@property (nonatomic) int bar;
@end

@implementation Foo
@synthesize bar = _bar;
   // stuff that does self.bar = 123;
@end

这样一些外部类不能调用foo.bar = 123 ..但是Foo里面的内部方法可以......?

1 个答案:

答案 0 :(得分:4)

在类扩展中将readwrite添加到nonatomic应该这样做:

@property (readwrite, nonatomic) int bar;