Я не уверен, что только для ivars, но если вы определили их как свойства, можно получить доступ к доступным свойствам класса.
Я использовал SQLitePersistentObjects для пары проектов, и у него есть некоторый полезный код, который получает свойства, определенные в классе, для использования при вычислении сериализации в sqlite и из sqlite.
Он использует функцию class_copyPropertyList для получения списка доступных свойств в классе.
Более конкретно:
+(NSDictionary *)propertiesWithEncodedTypes
{
// DO NOT use a static variable to cache this, it will cause problem with subclasses of classes that are subclasses of SQLitePersistentObject
// Recurse up the classes, but stop at NSObject. Each class only reports its own properties, not those inherited from its superclass
NSMutableDictionary *theProps;
if ([self superclass] != [NSObject class])
theProps = (NSMutableDictionary *)[[self superclass] propertiesWithEncodedTypes];
else
theProps = [NSMutableDictionary dictionary];
unsigned int outCount;
objc_property_t *propList = class_copyPropertyList([self class], &outCount);
int i;
// Loop through properties and add declarations for the create
for (i=0; i < outCount; i++)
{
objc_property_t * oneProp = propList + i;
NSString *propName = [NSString stringWithUTF8String:property_getName(*oneProp)];
NSString *attrs = [NSString stringWithUTF8String: property_getAttributes(*oneProp)];
NSArray *attrParts = [attrs componentsSeparatedByString:@","];
if (attrParts != nil)
{
if ([attrParts count] > 0)
{
NSString *propType = [[attrParts objectAtIndex:0] substringFromIndex:1];
[theProps setObject:propType forKey:propName];
}
}
}
free(propList);
return theProps;
}
Возвращает словарь свойств - вам нужно будет изучить результаты, которые вы получите, но вы сможете получить то, что вам нужно, если вы используете свойства.