Skip to content

Instantly share code, notes, and snippets.

@albertodebortoli
Created July 30, 2014 11:10
Show Gist options
  • Select an option

  • Save albertodebortoli/e95d642429a68d0b3aa7 to your computer and use it in GitHub Desktop.

Select an option

Save albertodebortoli/e95d642429a68d0b3aa7 to your computer and use it in GitHub Desktop.
Get the type of a property.
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