Last active
August 29, 2015 14:01
-
-
Save loganwright/912b1a23f157501572e1 to your computer and use it in GitHub Desktop.
Property Names / Attributes of Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <objc/runtime.h> | |
- (NSArray *) getPropertyNamesForClass:(Class)class { | |
NSMutableArray * propertyNames = [NSMutableArray array]; | |
// Fetch Properties | |
unsigned count; | |
objc_property_t *properties = class_copyPropertyList(class, &count); | |
// Parse Out Properties | |
for (int i = 0; i < count; i++) { | |
objc_property_t property = properties[i]; | |
const char * name = property_getName(property); | |
NSString * propertyName = [NSString stringWithUTF8String:name]; | |
[propertyNames addObject:propertyName]; | |
} | |
// Free our properties | |
free(properties); | |
return propertyNames; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment