I am newish to Objective-C. I am trying to determine if having a pointer for one class, then assigning an extended class to that pointer instead, will cause problems. For instance if ClassB extends ClassA, and I do this:
ClassA *foo = [[ClassB alloc] init];
Will this cause problems somewhere down the line? I know that Xcode seems to be okay with it, but that doesn’t mean it is okay.
Yes, that’s called polymorphism, you can do it without problems.
However since in Objective-C the message dispatching is dynamic, if the class B contains an overridden method, this one will be executed. This is often used when you know you’ll receive an object of a class that inherits from a known base class, but you don’t know which one. You can turn this to your advantage.