指定された初期化子を理解するのに問題があります。私は「MacでObjectiveCを学ぶ」という本からObjectiveCを勉強しています。以下は実装ファイルです。
#import "Tire.h"
@implementation Tire
- (id) init
{
if (self = [self initWithPressure: 34 treadDepth: 20]) {
}
return (self);
} // init
- (id) initWithPressure: (float) p
{
if (self = [self initWithPressure: p treadDepth: 20.0]) {
}
return (self);
} // initWithPressure
- (id) initWithTreadDepth: (float) td
{
if (self = [self initWithPressure: 34.0 treadDepth: td]) {
}
return (self);
} // initWithTreadDepth
- (id) initWithPressure: (float) p treadDepth: (float) td
{
if (self = [super init]) {
pressure = p;
treadDepth = td;
}
return (self);
} // initWithPressure:treadDepth:
私が理解していることから:
- (id) initWithPressure: (float) p treadDepth: (float) td
デフォルトの初期化子です。Tireクラスのインスタンスが次のようなステートメントで初期化される場合
Tire *aTire = [[Tire alloc] init];
その後、上記の初期化メソッドが実行されます。ただし、このメソッドには「pressure = p」が含まれているため、この段階まで「p」に値を指定していなかったため、圧力はどのようになりますか。また、このメソッドの実行が終了するとどうなりますか?キュー内の次の「init」メソッドはどれですか?