I have the following class definition.
Contact.h
Is it possible to get an array of NSString objects with all properties by name?
The array will look like this:
[@"City", @"LastUpdated", @"Country", .... ]
Solution (updated based on comment)
Thanks to Dave's answer, I was able to write the following method, which will be used
- (NSMutableArray *) propertyNames: (Class) class { NSMutableArray *propertyNames = [[NSMutableArray alloc] init]; unsigned int propertyCount = 0; objc_property_t *properties = class_copyPropertyList(class, &propertyCount); for (unsigned int i = 0; i < propertyCount; ++i) { objc_property_t property = properties[i]; const char * name = property_getName(property); [propertyNames addObject:[NSString stringWithUTF8String:name]]; } free(properties); return [propertyNames autorelease]; }
source share