我该怎么做:
@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里面的内部方法可以......?
答案 0 :(得分:4)
在类扩展中将readwrite
添加到nonatomic
应该这样做:
@property (readwrite, nonatomic) int bar;