How do I list all fields of an object in Objective-C?
2015-01-30 14:39
555 查看
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:
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 get the name of an object's type in JavaScript
- How do I list all tables/indices contained in an SQLite database
- How do I convert an enum to a list in C#?
- How do you copy the contents of an array to a std::vector in C++ without looping? (From stack over flow)
- How do I sort an array of hashes by a value in the hash?
- How to copy an object in objective c
- How do you make an object in C? Used in RTOS.
- How one VBA project can use an object declared in the class module of another project
- How do I convert an enum to a list in C#?
- How to access the properties of an object in Javascript
- How to get an icon of an object in Windchill
- How do I make my GUI plot into an axes within the GUI figure rather than inside of a new figure in M
- How do I apply a style to all buttons of an Android application
- All-In-One Code Framework(AIO): 如何使用C#编写进程外的COM组件 (How to write an out-of-proc COM server in C#)
- How do I check if a type is a subtype OR the type of an object?
- How do I sort an array of hashes by a value in the hash?
- Item 12: Copy all parts of an object(Effective C++)
- 处理教材:Everything is an object of "Thinking in Java"
- 20100507 学习记录: Server Error in '/' Application. Object reference not set to an instance of an object
- How Would You Get the Count of an Array in C++?