If I have an NSObject
subclass which either has no -init
method or simply does nothing in -init
, is there any difference between an instance created these two ways:
MyClass *instance = [MyClass alloc];
MyClass *instance = [[MyClass alloc] init];
By "does nothing in -init
" I mean
- (id)init {
self = [super init];
if (self) {
}
return self;
}
Since NSObject
's -init
method itself does nothing, I can't see there being any difference, but of course the advice is that you must call -init
to properly prepare an object.
Here's the snippet from NSObject
's -init
method which got me wondering about this:
The init method defined in the NSObject class does no initialization; it simply returns self.