Iphone:如何获取类的所有属性?

Iphone:如何获取类的所有属性?,iphone,reflection,runtime,Iphone,Reflection,Runtime,我有这门课: @interface Mission : BaseModel { NSString *Description; NSDate *EndDate; NSMutableArray *MissionSectionList; NSString *Name; NSDate *StartDate; } @property (nonatomic, retain) NSString *Description; @property (nonatomic, retain) NSDate

我有这门课:

@interface Mission : BaseModel  
{
NSString  *Description;
NSDate  *EndDate;
NSMutableArray  *MissionSectionList;
NSString  *Name;
NSDate  *StartDate;
}
@property (nonatomic, retain) NSString  *Description;
@property (nonatomic, retain) NSDate  *EndDate;
@property (nonatomic, retain) NSMutableArray  *MissionSectionList;
@property (nonatomic, retain) NSString  *Name;
@property (nonatomic, retain) NSDate  *StartDate;
@end
有可能找出这个类的所有属性吗? 我试过了

Ivar类_getClassVariable(类cls,常量字符*名称)

但我不知道该叫什么名字:

名称:要获取的类变量定义的名称

事实上,我想在不知道名字的情况下得到它们


这可能吗?

您可以使用
class\u copyIvarList
函数获取该类的所有实例变量的列表。然后您可以遍历它以获得每个ivar的属性。(请注意,您负责释放用于ivars阵列的内存)。示例代码可能如下所示:

unsigned int count;
Ivar *varList = class_copyIvarList([Mission class],&count);
for (int i = 0; i < count; ++i){
    Ivar var = varList[i];
    // Do when you need with ivar
}
free(varList);
无符号整数计数;
Ivar*varList=class_copyIvarList([任务类],&count);
对于(int i=0;i
制作一个返回具有这些属性的数组的方法怎么样?但这可能是一种不好的方法:)你想找到哪些关于属性的信息?上面说你不想要名字,你想知道它们是什么类型吗?我实际上想要名字和类型。我不确定参数的名称是什么。因为我想知道名字。谢谢!如何输出var?我做了NSLog(@“我的属性:%@”,var);但是它说EXC_BAD_ACCES.Ivar是指向一个结构的指针,而不是一个obj-c类——您不能直接使用NSLog输出它。使用ivar\u getName、ivar\u getTypeEncoding、ivar\u getOffset函数获取ivar属性。啊,好的。酷。谢谢你的回答。这正是我所需要的:——)