Created
July 30, 2014 11:10
-
-
Save albertodebortoli/e95d642429a68d0b3aa7 to your computer and use it in GitHub Desktop.
Get the type of a property.
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
| static const char *getPropertyType(objc_property_t property) { | |
| const char *attributes = property_getAttributes(property); | |
| char buffer[1 + strlen(attributes)]; | |
| strcpy(buffer, attributes); | |
| char *state = buffer, *attribute; | |
| while ((attribute = strsep(&state, ",")) != NULL) { | |
| if (attribute[0] == 'T' && attribute[1] != '@') { | |
| NSString *name = [[NSString alloc] initWithBytes:attribute + 1 length:strlen(attribute) - 1 encoding:NSASCIIStringEncoding]; | |
| return (const char *)[name cStringUsingEncoding:NSASCIIStringEncoding]; | |
| } | |
| else if (attribute[0] == 'T' && attribute[1] == '@' && strlen(attribute) == 2) { | |
| return "id"; | |
| } | |
| else if (attribute[0] == 'T' && attribute[1] == '@') { | |
| NSString *name = [[NSString alloc] initWithBytes:attribute + 3 length:strlen(attribute) - 4 encoding:NSASCIIStringEncoding]; | |
| return (const char *)[name cStringUsingEncoding:NSASCIIStringEncoding]; | |
| } | |
| } | |
| return ""; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment