【发布时间】:2014-01-24 22:48:16
【问题描述】:
关注this blog post,我看到了解决我面临的问题的方法。
和他一样,我的问题是我有一个类,该类具有必须在其子类中继承和访问的属性:
@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
我想知道是否还有另一种方法可以将属性声明为受保护?
【问题讨论】:
标签: objective-c inheritance properties ivar