작동합니다. 내가 책에서 목표 C를 공부하고 있습니다 "Mac에서 목표 C 알아". 다음은 실행 파일입니다. 내가 이해에서방법을 지정 않습니다 초기화 내가 지정된 이니셜을 이해하는 몇 가지 문제가 있어요
#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];
과 같은 명령문으로 초기화 될 때 위의 초기화 메소드가 실행됩니다. 상기 방법은 "압력 = P"를 포함하기 때문에 그러나,이 단계까지 우리는 "P"값 지정되지 않았으므로 동일 압력하는 것이다. 이 방법은 실행을 완료 한 후 또한, 무슨 일이? 다음에 대기열에있는 "init"메소드는 무엇입니까? initWithPressure: (float) treadDepth: (float)
방법은 명시 적으로 호출하기 때문에 타이어 클래스 방법