首页 > 代码库 > How do I list all fields of an object in Objective-C?
How do I list all fields of an object in Objective-C?
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?
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。