Is it possible to return a list of all the properties implemented by an object in Objective-C? I understand the properties are just getters and setters so I'm not sure how it would work. If this cannot be done, then is it possible to return all the selectors that an object will respond to? I'm looking for something similiar to the "methods" method in Ruby.
+3
A:
// Get properties list
objc_property_t* class_copyPropertyList(Class cls, unsigned int *outCount);
// Get methods list
Method* class_copyMethodList(Class cls, unsigned int *outCount);
The following code will output all methods implemented in UIImage class to console:
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);
Vladimir
2010-03-09 15:20:57
Looks great, Thanks! What do I need to import to get objc_property_t?
Joe Cannatti
2010-03-09 15:28:02
nevermind, i got it. -- #import <objc/runtime.h>
Joe Cannatti
2010-03-09 15:30:17
+1
A:
I was actually trying out this yesterday and it is possible, however you cannot get everything from UIView. Take a look at the Objective-C Runtime Reference
Tuomas Pelkonen
2010-03-09 15:22:10