I have a Class with an instance variable of an NSArray of different objects I know should inherit from the same superclass. My question is how do I access the instance variables and methods from another class (its controller) while ensuring that the contents of the array contains only objects that are a subclass of a certain class? I tried implementing a minimal protocol and refencing the objects in the array as type id and (id *) but that won’t let me access any instance variables or methods of the classes in the array (and rightly so).
In object file
NSArray* components; // contains subclasses of component
In the controller file
subclassofClassObject* object;
is there a subclassOf function, macro, typedef … etc or a workaround so I can reference the subclasses of component in a subclass of object from a subclass of controller. i.e something to replace subclassofClass.
I don’t quite follow what you’re asking, but maybe the following will help:
You can determine if you have an instance of a class, or one of its subclasses using
isKindOfClass:. For example given a classMyBaseClass, then use a cast: