Мне нужно определить тип объекта (переданный по имени), чтобы выполнить десериализацию из XML. У меня есть общий псевдокод (однако я не уверен, как выполнять эти сравнения в Objective-C):
id object = [[[Record alloc] init] autorelease];
NSString *element = @"date";
NSString *data = @"2010-10-16";
objc_property_t property = class_getProperty([object class], [element UTF8String]);
const char *attributes = property_getAttributes(property);
char buffer[strlen(attributes) + 1];
strcpy(buffer, attributes);
char *attribute = strtok(buffer, ",");
if (*attribute == 'T') attribute++; else attribute = NULL;
if (attribute == NULL);
else if (strcmp(attribute, "@\"NSDate\"") == 0) [object setValue:[NSDate convertToDate:self.value] forKey:element];
else if (strcmp(attribute, "@\"NSString\"") == 0) [object setValue:[NSString convertToString:self.value] forKey:element];
else if (strcmp(attribute, "@\"NSNumber\"") == 0) [object setValue:[NSNumber convertToNumber:self.value] forKey:element];
Я просмотрел class_getProperty и property_getAttributes, однако я до сих пор не уверен, как выполнить приведенные выше сравнения.