iPhone:如何获取一个类的所有属性?
我有这个类:
@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 class_getClassVariable(Class cls, const char* name)
但我不知道名称应该是什么:
name:要获取的类变量定义的名称。
事实上我想在不知道名字的情况下得到所有这些。
这可能吗?
I have this class:
@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
Is it possible to find out all the atrributes of this class?
I tried it with
Ivar class_getClassVariable(Class cls, const char* name)
But I don't know what the name should be:
name: The name of the class variable definition to obtain.
And actually I want to get all of them without knowing the name.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
class_copyIvarList
函数获取该类的所有实例变量的列表。然后你可以迭代它来获取每个 ivar 的属性。 (请注意,您负责释放用于 ivars 数组的内存)。示例代码可能如下所示:You can use
class_copyIvarList
function to get the list of all instance variables of the class. Then you can iterate through it to get attributes of each ivar. (Note that you're responsible for freeing memory used for ivars array). Sample code may look like: