views:

53

answers:

2
- (id) init
{
     [super init];
     //initialitation of the class
     return self;
}

I know that when I am inheriting from another class I am suppose to call super.init

Does this apply to "inheriting from NSObject" ?

+5  A: 

Yes, usually you have something like:

- (id) init
{
    if (self = [super init]) {
        // instantiation code
    }

    return self;
}
Jorge Israel Peña
A: 

Technically, yes, because Apple's documentation says init... methods should always include a call to super. However at present, the NSObject implementation of -init does nothing, so omitting the call wouldn't prevent your code from working.

The downside of omitting the call to super is that your code wouldn't be as robust to future changes; for example if you later changed the inheritance, or if (God forbid) Apple changed NSObject's -init method so that it actually did something essential.

jlehr