看來我應該實現三個初始化器。主要的初始化器是調用[super init]的初始化器,並且所有變量都在此方法中分配。但是由於其他兩個初始化器具有非重疊參數,它們都稱爲主初始化器。非重疊對象初始化
這種方法是否正確?在許多例子中,第三級初始化器調用第二級,然後第二級調用第一級,而第一級和第二級直接調用第一級初始化器。
-(id)initWithAccount:(NSString *)account_name apiKey:(NSString *)api_key lineid:(NSString *)line_id runTitle:(NSString *)run_title data:(NSString *)stringData runID:(NSString *)run_id{
if(self = [super init]){
accountName = [account_name retain];
runID = [run_id retain];
apiKey = [api_key retain];
lineID = [line_id retain];
data = [stringData retain];
runTitle = [run_title retain];
}
return self;
}
-(id)initWithAccount:(NSString *)account_name apiKey:(NSString *)api_key runID:(NSString *)run_id{
return [self initWithAccount:account_name apiKey:api_key lineid:nil runTitle:nil data:nil runID:run_id];
}
-(id)initWithAccount:(NSString *)account_name apiKey:(NSString *)api_key lineID:(NSString *)line_id{
return [self initWithAccount:account_name apiKey:api_key lineid:line_id runTitle:nil data:nil runID:nil];
}