Joe*_*tti 10 iphone objective-c
是否可以返回Objective-C中对象实现的所有属性的列表?我知道属性只是getter和setter所以我不确定它是如何工作的.如果无法做到这一点,那么是否可以返回对象将响应的所有选择器?我正在寻找类似于Ruby中"methods"方法的东西.
Vla*_*mir 19
// Get properties list
objc_property_t* class_copyPropertyList(Class cls, unsigned int *outCount);
// Get methods list
Method* class_copyMethodList(Class cls, unsigned int *outCount);
Run Code Online (Sandbox Code Playgroud)
以下代码将UIImage类中实现的所有方法输出到控制台:
unsigned int count;
Method* methods = class_copyMethodList([UIImage class], &count);
for (size_t i = 0; i < count; ++i)
NSLog([NSString stringWithCString:sel_getName(method_getName(methods[i]))]);
free(methods);
Run Code Online (Sandbox Code Playgroud)