i am currently reading the “Programming with Objective C” manual from Apple and it shows these two init methods. what is the difference between them and when would each one be appropriate to use?
- (id)initWithFirstName:(NSString *)aFirstName lastName:(NSString *)aLastName dateOfBirth: (NSDate *)aDateOfBirth {
self = [super init];
if (self) {
_firstName = aFirstName;
_lastName = aLastName;
_dateOfBirth = aDateOfBirth;
}
return self;
}
vs
- (id)initWithFirstName:(NSString *)aFirstName lastName:(NSString *)aLastName {
return [self initWithFirstName:aFirstName lastName:aLastName dateOfBirth:nil];
}
manual can be found here http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html#//apple_ref/doc/uid/TP40011210-CH5-SW15
The second one is circular and will lead to infinite recursion.
edit:
With the updated question, the second version of the initializer is just a convenience because you no longer need to specify the third parameter.