私はこのコードを継承しました:
- (id)initWithLocation:(CLLocation *)inLocation {
if (self = [super init])
{
_location = [inLocation copy];
}
return self;
}
- (id)initWithLocation:(CLLocation *)inLocation offsetValue:(NSNumber *)offset {
if (self = [super init])
{
_location = [inLocation copy];
_offset = [offset copy];
}
return self;
}
そして、最初のメソッドが指定されたイニシャライザを呼び出さない正当な理由があるかどうか疑問に思っています (たとえば、このように、 init メソッドで init メソッドを自分で呼び出しても問題ありませんか? )?
つまり、なぜこれをしないのですか:
- (id)initWithLocation:(CLLocation *)inLocation {
if (self = [super init])
{
[self initWithLocation:inLocation offsetValue:nil];
}
return self;
}
- (id)initWithLocation:(CLLocation *)inLocation offsetValue:(NSNumber *)offset {
if (self = [super init])
{
_location = [inLocation copy];
_offset = [offset copy];
}
return self;
}