Reputation: 11
I understand the purpose of having an initializer is to set the instance variables to certain values. However, I am confused as to why you would want to have multiple initializers for each instance variable. Can't one initializer set all the instance variables? I guess my question really is what is the practicality of having multiple initializers in a class. For instance a class has the following:
- (id)initWithItemName:(NSString *)name
{
return [self initWithItemName:name valueInDollars:0 serialNumber:@""];
}
Meanwhile the designated initializer is given as such:
- (id) initWithItemName:(NSString *)name valueInDollars:(int)value
serialNumber:(NSString *)sNumber;
The designated initializer, as you can see, already initializes the itemName variable. So, whats the pont of having a specific initializer just for one variable.
Upvotes: 1
Views: 96
Reputation: 2236
Upvotes: 1