Created
February 25, 2013 01:15
-
-
Save tyrone-sudeium/5026677 to your computer and use it in GitHub Desktop.
Same as the built-in class_copyPropertyList except it traverses the class hierarchy too.
This file contains 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 objc_property_t* class_copyPropertyList_recursive(Class aClass, unsigned int *outCount) | |
{ | |
unsigned int total = 0; | |
objc_property_t *contiguousList = nil; | |
objc_property_t *ptr = nil; | |
unsigned int ptrOffset = 0; | |
unsigned int listLen = 0; | |
unsigned int const increment = 32; | |
contiguousList = malloc(sizeof(objc_property_t) * increment); | |
listLen = increment; | |
ptr = contiguousList; | |
while (aClass != nil && aClass != [NSObject class] && contiguousList != nil) { | |
objc_property_t *currentList = nil; | |
unsigned int count = 0; | |
currentList = class_copyPropertyList(aClass, &count); | |
total += count; | |
if (total > listLen) { | |
unsigned int increase = increment * ceil(((double)total - (double)listLen) / increment); | |
listLen = listLen + increase; | |
contiguousList = realloc(contiguousList, sizeof(objc_property_t) * listLen); | |
if (contiguousList == nil) { | |
total = 0; | |
break; | |
} | |
ptr = contiguousList + ptrOffset; | |
} | |
memcpy(ptr, currentList, sizeof(objc_property_t) * count); | |
ptr += count; | |
free(currentList); | |
aClass = [aClass superclass]; | |
} | |
if (outCount) { | |
*outCount = total; | |
} | |
return contiguousList; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment