Is it possible to do something like the following in Objective-c?
NSString *propertyName = NSStringFromSelector(aPerson.personName);
propertyName
would have the string personName
;
I would like to put this into a category of NSObject
.
Is it possible to do something like the following in Objective-c?
NSString *propertyName = NSStringFromSelector(aPerson.personName);
propertyName
would have the string personName
;
I would like to put this into a category of NSObject
.
To get all the property names of a class
- (NSMutableArray *)getAllPropertyOfClass:(Class)aClass {
NSMutableArray *mArray=[NSMutableArray new];
unsigned int outCount;
objc_property_t *properties = class_copyPropertyList([aClass class], &outCount);
for(unsigned int i = 0; i < outCount; i++) {
objc_property_t property = properties[i];
const char *propName = property_getName(property);
if(propName) {
NSString *propertyName = [NSString stringWithUTF8String:propName];
mArray[mArray.count]=propertyName;
}
}
free(properties);
return mArray;
}