Possible Duplicate:
In Objective-C why should I check if self = [super init] is not nil?
In Objective-C book i am reading, it is said that when [init] message is sent to NSObject, on occasion it may return nil and we should check the return value, before sending more messages to what may end up being a nil.
self = [super init];
if (self) {
do stuff
}
I ask you though, what needs to happen for an NSObject to not be able to init itself?
Edit: Question specifically deals with an instance where YourClass:NSObject.
NSObjectitself will never return nil oninit, however other classes that inherit from it might, so it’s considered good practice to always check the return value ofinit. For example, this will return nil: