I'm trying create a superclass whom I know will be subclassed (I would make the object abstract, but according to Creating an abstract class in Objective-C , you can't). The superclass defines a method, -initWithArguments:
, that just throws an error because it's overridden by subclasses. The superclass also has a static initializer that determines which subclass to return at runtime, like so:
Class subClass = NSClassFromString(classNameFromFile);
NSArray *argumentArray = [ArgumentsFromFile componentsSeparatedByString:@","];
SuperClass *returnObject = [[subClass alloc] initWithArguments:argumentArray];
if([returnObject isKindOfClass:[SuperClass class]]){
return returnObject;
}
I expect that the overridden -initWithArguments:
method will be called here in line 3. However, when I run this code, only the superclass's -initWithArguments:
ever gets called. I have checked and double checked that the overridden method signature is correct, and I've confirmed that subClass correctly represents the subclass. What the hell? Does this have to do with the fact that I'm calling the -initWithArguments:
inside the superclass? Thanks in advance for help; I love you all.