One approach you can take, assuming you know the property name already, is to use the class_getProperty
function. You can also use the property_copyAttributeValue()
function to get just a particular attribute by name:
objc_property_t number_property = class_getProperty([MyClass class], "number");
char *number_property_type_attribute = property_copyAttributeValue(number_property, "T");
NSLog(@"number property type attribute = %s", number_property_type_attribute);
Will log:
2013-01-14 14:45:37.382 RuntimeFun[61304:c07] number property type attribute = i
Assuming MyClass
looks something like:
@interface MyClass : NSObject
@property (nonatomic) int number;
@end
@implementation MyClass
@end
One you have your type attribute string, you can then compare it to the various Objective-C type encodings. Once you're done with your comparison, be sure to call free()
on your attribute string.