Objective C reflection for iOS

I would like to be able to use reflection in classes in Objective-C to determine which properties are available at runtime.

I'm doing something similar for classes right now using

NSString *str = NSStringFromClass([object class]); 

What I would like to do is use this result to return to the class and see what properties are available, as well as the type of these properties.

+4
source share
1 answer

Perhaps this will help:

You can get a list of properties in a class using class_copyPropertyList

 objc_property_t * class_copyPropertyList(Class cls, unsigned int *outCount) 

and then from each property you can get the property name using the property_getName function and property_getName attributes using the property_getAttributes function (if you need to filter read and write properties).

+7
source

Source: https://habr.com/ru/post/1446140/


All Articles