In Stephen Kochan’s Objective-C book (I have the 3rd Edition), one init function returns Fraction * and one returns id:
-(Fraction *) initWith: (int) n: (int) d {
self = [super init];
if (self)
[self setTo: n over: d];
return self;
}
-(id) init {
return [self initWith: 0 over: 0];
}
(it is on page 198 to 199 of the book). Why is that, and does it matter if both return Fraction * or both return id (or have init return Fraction * and initWith return id)? What are the side effects of doing so, if any?
Initmethods typically return theidtype because they don’t necessarily return an object of the class they belong to.For instance,
-[NSMutableArray init]actually returns aNSCFMutableArrayobject.