在我的应用程序中,我应该分析一个对象,我这样做: if ([object_selected isKindOfClass:[Person class]]) { Persone *obj = (Persone*)object_selected; NSString *name = obj.nome; NSString *surname = obj.surname;}else if ([objec
if ([object_selected isKindOfClass:[Person class]]) { Persone *obj = (Persone*)object_selected; NSString *name = obj.nome; NSString *surname = obj.surname; } else if ([object_selected isKindOfClass:[Animal class]]) { Animal *obj = (Animal*)object_selected; NSString *name = obj.nome; NSString *breed = obj.breed; }
通过这种方式,我应该验证我的对象是否属于一个类以获取其属性,但是有更快的方法从我的对象获取属性“name”吗?
所有对象都具有“name”属性.
谢谢
您可以只调用[object_selected name],但是您可能会收到名称可能不是属性(或类似名称)的编译器警告.