I have a base class called ModelBase and I have a derived class called “Person”.
Now in the init method of person, I have something like
-(Person*) init {
if(self = [super init])
return self;
return nil;
}
However, Objective C complains that
Incompatible Objective-C types initializing ‘struct ModelBase *’, expected ‘struct Person *’. I’m only initializing self with [super init] which is initializing a base class pointer to a derived class.
What am I missing?
Did you declare your ModelBase init method to return (ModelBase*) ? If so, change it to return (id) instead. You’ll notice that most initializers in Cocoa return (id) for this very reason.
Instead of
you want