What is the proper way of overloading init methods with variable param number? I'm doing it:
- (id)initWithInt:(int)a
开发者_高级运维{
return [self initWithInt:a andString:nil];
}
-(id)initWithInt:(int)a andString:(NSString*)str
{
self = [super init];
if (self) {
NSLog(@"%@ %i",str,a);
}
return self;
}
It works, but the return [self initWithInt:a andString:nil];
does not seem right to me(there is no self at the moment, right?)
No, this is perfectly valid. Self is already setup, the idiom of reassigning self is for a couple of different edge cases (initialization fails, the initializer wants to return a different instance then the one you allocated, etc).
精彩评论