Objective c 使用isKindOfClass输出数组中对象的子对象?

Objective c 使用isKindOfClass输出数组中对象的子对象?,objective-c,inheritance,Objective C,Inheritance,我有一个cocos2d游戏设置,它使用与此类似的基本继承设置 > Property (Base class) > - Office : Property > - Warehouse : Property > - Bank : Property 所有属性都位于一个数组listOfProperties中,我正试图在NSLog中打印出每个属性,但我不知道如何执行 比如说, // Create an office Office *o = [Office alloc] init]

我有一个cocos2d游戏设置,它使用与此类似的基本继承设置

> Property (Base class)
> - Office : Property
> - Warehouse : Property
> - Bank : Property
所有属性都位于一个数组
listOfProperties
中,我正试图在NSLog中打印出每个属性,但我不知道如何执行

比如说,

// 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
问题是某些属性不共享相同的属性。例如,办公室可能有“楼层”,但仓库有“容量”

我需要的是打印出所有不同的属性,但我不确定如何将焦点从指针
prop
更改为特定类(即Office)的指针

我需要它们都生活在
属性列表中
,这样我以后可以在ccmen中使用它,并且希望避免将它们分割成单独的数组,这对我来说是非常难以管理的

有办法做到这一点吗


谢谢你这样打字

for (Property *prop in city.listOfProperties) {

 if ([prop isKindOfClass:[Office class]])
 {
     Office* officeObject = (Office*) prop;

     NSLog(@"office.name = %@", officeObject.name);
 }
 if ([prop isKindOfClass:[Warehouse class]])
 {
     Warehouse* WarehouseObject = (Warehouse*) prop;

     NSLog(@"Warehouse.name = %@", WarehouseObject.name);
 }
 if ([prop isKindOfClass:[Bank class]])
 {
     Bank* BankObject = (Bank*) prop;

     NSLog(@"Bank.name = %@", BankObject.name);
 }
}


您可以有任何要记录的变量。例如使用名称。

注意。并非属性的所有子节点都有
名称
。这仅用于说明目的。有些根本没有名字