我想继承我的几个派生类将使用的基类属性和方法。我希望这些属性和方法得到完全保护,以便它们只能在派生类中显示,而不能在任何外部类中显示。但它总是给我一些错误。目标中的属性继承C
@interface BasePerson : NSObject
@end
@interface BasePerson()
@property (nonatomic, strong) NSMutableArray<Person*>* savedPersons;
@property (nonatomic) BOOL shouldSavePerson;
@end
@interface DerivedPerson1 : BasePerson
@end
@implementation DerivedPerson1
- (instancetype)init
{
if (self = [super init]) {
self.savedPersons = [NSMutableArray array];
self.shouldSavePerson = NO;
}
return self;
}
它总是给我
Property 'savedPersons' not found on object of type 'DerivedPerson1 *'
Property 'shouldSavePerson' not found on object of type 'DerivedPerson1 *'
我怎样才能让目标C使用继承的,我不想savedPersons和shouldSavePerson属性是外部类可见的错误。我只希望它们在我的基类和所有派生类中可见。
任何帮助将是伟大的。谢谢
你能否让我知道派生类的父类名称。 它是UIViewController还是NSObject? –
它的NSObject。这有什么区别吗? – Madu
你的代码看起来不错,不会在编译时大喊错误 – Tj3n