相关疑难解决方法(0)

具有合成readonly属性的类的子类无法访问Objective-C中的实例变量

在超类中MyClass:

@interface MyClass : NSObject

@property (nonatomic, strong, readonly) NSString *pString;

@end

@implementation MyClass

@synthesize pString = _pString;

@end
Run Code Online (Sandbox Code Playgroud)

在子类中 MySubclass

@interface MySubclass : MyClass

@end

@implementation MySubclass

- (id)init {
    if (self = [super init]) {
        _pString = @"Some string";
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

问题是编译器不认为它_pString是成员MySubclass,但我在访问它时没有问题MyClass.

我错过了什么?

inheritance subclass objective-c ios

26
推荐指数
2
解决办法
1万
查看次数

标签 统计

inheritance ×1

ios ×1

objective-c ×1

subclass ×1