码迷,mamicode.com
首页 > 其他好文 > 详细

How do I list all fields of an object in Objective-C?

时间:2015-01-30 16:52:16      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

http://stackoverflow.com/questions/1213901/how-do-i-list-all-fields-of-an-object-in-objective-c

As mentioned, you can use the Objective-C runtime API to retrieve the instance variable names:

unsigned int varCount;

Ivar *vars = class_copyIvarList([MyClass class], &varCount);

for (int i = 0; i < varCount; i++) {
    Ivar var = vars[i];

    const char* name = ivar_getName(var);
    const char* typeEncoding = ivar_getTypeEncoding(var);

    // do what you wish with the name and type here
}

free(vars);

How do I list all fields of an object in Objective-C?

标签:

原文地址:http://www.cnblogs.com/xuejinhui/p/4262304.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!