I’ve been working with this
objc_property_t *properties = class_copyPropertyList([NSString class], &outCount);
which has two limitations that I don’t know how to resolve:
- It doesn’t list inherited properties.
- I can’t differentiate IBOutlets from other properties.
How can I dynamically list all the IBOutlet properties in a class (or instance)?
IBOutletis#defined as a blank string; it doesn’t have any effect at either compile or run time. Its sole purpose is to allow Interface Builder to look at header files and see which ivars should be used as connections. The only way for you to determine which ivars were declared asIBOutlets would be to likewise do some text processing of the header file of whatever class you’re working with.For the properties, I’m not sure there’s any other way than going up the list of superclasses and getting all their properties too. You can call
class_getSuperclassin a loop to get the whole ancestry of your class;* the function returnsNilwhen you call it with the root class (NSObject) as the argument.*See, e.g., this SO answer of mine.