I've come across a strange scenario related to class inheritance in Objective-C.
Let's say i have three classes A, B and C that inherit from a base class X. Classes A, B and X have the constructor:
- (id)InitWithString:(NSString*)someString andDelegate:(id<SomeProtocol>)aDelegate
the only difference being that every class uses a different protocol for the delegate.
What happens is that for A and B the compiler tries to use the method from C. A warning informs me that the protocols required by class C's constructor is not implemented by the provided delegate. There is nothing wrong with the delegate itself, since each class has a delegate that implements the right protocol for the classes' own constructor. Everything works fine at run time and the right functions are called for all classes.
I tried having the constructors return A*, B* or C* instead of the anonymous id, though this still doesn't solve the problem.
The only thing that works is making a cast to the right class like this:
instanceOfA = [(A*)[A alloc] InitWithString:@"" andDelegate:aDelegate];
This seems superfluous and unnecessary. I'm probably missing something obvious here.