Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property reflection in Objective C for iOS

I would like to be able to use reflection on a classes within Objective C to determine what properties are available at run time.

I do something similar for classes right now using

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

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

like image 358
bigtunacan Avatar asked Nov 15 '12 05:11

bigtunacan


1 Answers

May be this will help:

You can get the 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 property_getName function and the property attributes using the property_getAttributes function (if you need to filter read-write properties).

like image 132
MrWaqasAhmed Avatar answered Oct 20 '22 15:10

MrWaqasAhmed