views:

56

answers:

2

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
Looks great, Thanks! What do I need to import to get objc_property_t?
Joe Cannatti
nevermind, i got it. -- #import <objc/runtime.h>
Joe Cannatti
+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