在这篇博文之后,我看到了一种解决我面临的问题的方法。
我的问题和他一样,是我有一个类,它有一个必须在其子类中继承和访问的属性:
@interface A : NSObject
@property (nonatomic, readonly) NSUInteger prop;
@end
@implementation A
// Don't need to synthesize nowadays
@end
@interface B : A
// No new properties
@end
@implementation B
- (void)establishValueForProp
{
_prop = 1; // PROBLEM !!!
}
@end
解决方案是这样的:
@interface A : NSObject {
@protected
NSUInteger _prop;
}
@property (nonatomic, readonly) NSUInteger prop;
@end
我想知道是否还有另一种方法可以将属性声明为受保护?