-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Labels
Description
- (NSString *)propertyNameForObject:(NSObject *)object byCaseInsensitivePropertyName:(NSString *)caseInsensitivePropertyName
{
NSString *result = nil;
Class currentClass = [object class];
NSString *key = [NSString stringWithFormat:@"%@.%@", NSStringFromClass(currentClass), caseInsensitivePropertyName];
if (self.propertyNameDictionary[key])
return self.propertyNameDictionary[key];
while (currentClass && currentClass != [NSObject class])
{
unsigned int outCount, i;
objc_property_t *properties = class_copyPropertyList(currentClass, &outCount);
for (i = 0; i < outCount; i++)
{
objc_property_t property = properties[i];
NSString *propertyName = [NSString stringWithUTF8String:property_getName(property)];
if ([[propertyName lowercaseString] isEqual:[caseInsensitivePropertyName lowercaseString]])
{
result = propertyName;
break;
}
}
free(properties);
if (result)
{
self.propertyNameDictionary[key] = result;
return result;
}
currentClass = class_getSuperclass(currentClass);
}
return nil;
}
Do a null check on properties before calling free
Also do a null check for key?