Possible Duplicate:
Why should I call self=[super init]
I been reading a book of Objective C, and to create a class that contains other classes (composition) it uses the self = [super init]
- (id) init
{
if (self = [super init]) {
engine = [Engine new];
tires[0] = [Tire new];
tires[1] = [Tire new];
tires[2] = [Tire new];
tires[3] = [Tire new];
}
return (self);
} // init
And when he is creating another classes he doesn't include this init method, i understand that it need to initialize the instance objects it will be using, but i don't understand why is he putting the self = [super init] and when a class needs this statement.
@interface Tire : NSObject
@end // Tire
@implementation Tire
- (NSString *) description
{
return (@"I am a tire. I last a while");
} // description
@end // Tire