iphone - Why put [super init] inside of an if statement since whether or not the return is nil we return it anyway? -


on cs193p course says in init method there should if statement check if [super init] works:

if (self = [super init]) {     self.someproperty = parameter;     } return self; 

i don't understand why done, if [super init] returns nil, method return nil, no matter outcome of if statement?

edit: question is; why put self = [super init] inside if statement. (not: why have self = [super init] @ all)

that's make sense because in cases [super init] can return nil, , in case if try access ivar you'll crash.

example:

-(id) init {     self = [super init];     some_ivar = [[nsobject alloc] init]; //compiler treats self->some_ivar     //if self == nil you'll exc_bad_access      return self; } 

Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -