I have a cocos2d game setup which uses basic inheritance setup which is similar to this;
> Property (Base class)
> - Office : Property
> - Warehouse : Property
> - Bank : Property
All the properties live in an array listOfProperties
and I am trying to print out each property in a NSLog, but I am not sure how to do it.
For example,
// Create an office
Office *o = [Office alloc] init];
[o setName:@"Some office"];
[city.listOfProperties addObject:o];
[o release];
// Debug output all the properties in the game
// city.listOfProperties in an array of Property objects
for (Property *prop in city.listOfProperties) {
// I want to print out all the different properties here
if ([prop isKindOfClass:[Office class]]==YES)
{
NSLog(@"Office");
NSLog(@"office.name = %@", prop.name); // Prop name does not work
}
} // next
The problem is that some properties do not share the same attributes. For example, an Office might have "floors" but a Warehouse has "capacity".
What I'm needing is to print out all the different properties, but I am not sure how to change the focus from the pointer prop
to a pointer for the specific class (ie: Office).
I need them all to live in listOfProperties
so that I can use it later on in a CCMenu and want to avoid splitting them up into seperate arrays which will be very hard for me to manage.
Is there a way to do this?
Thanks