私はクラスを持っています:
BasicObject : NSObject
AdvObject : BasicObject
他のクラスでは、次の方法でインスタンスを作成します。
BasicObject *bObj = [[BasicObject alloc] initWithSomething:propertyOne andSomethingElse:propertyTwo];
BasicObject には次の 2 つのプロパティがあります。
@interface BasicObject : NSObject
-(id)initWithSomething:propertyOne andSomethingElse:propertyTwo;
@property (strong,nonatomic) NSString* propertyOne;
@property (strong,nonatomic) NSArray* propertyTwo;
そして、初期化子で:
-(id)initWithSomething:propertyOne andSomethingElse:propertyTwo
{
if (self = [super init])
{
_propertyOne = propertyOne;
_propertyTwo = propertyTwo;
if(!propertyTwo) //this is not valid condition i know, not important here
{
AdvObject *aObj = [[AdvObject alloc] initWithBasic:self]; //here it what i'm more concern about
return aObj;
}
}
return self;
}
したがって、初期化子の AdvObject クラスには次のものがあります。
@implementation AdvObject
@synthesize basics = _basics;
-(id)initWithBasic:(BasicObject *)bObj
{
if(self = [super init]) {
_basics = bObj;
}
return self;
}
その後、もちろんこのオブジェクトを返すと、object.basics が適切に埋められますが、なぜ object.propertyOne にアクセスできないのでしょうか? (これはゼロです)。私が間違っているのは何ですか?これは正しい設計ですか?