tipo de propriedade ou classe usando reflexão
Eu queria saber se é possível determinar a classe ou o tipo primitivo de uma propriedade Objetos. Obter todos os nomes e valores de propriedades é muito fácil.Então responde
Então, existe alguma maneira de obter o tipo de classe de propriedades enquanto a propriedade não tiver valor ou valor nulo?
Exemplo de código
@interface MyObject : NSObject
@property (nonatomic, copy) NSString *aString;
@property (nonatomic, copy) NSDate *aDate;
@property NSInteger aPrimitive;
@end
@implementation MyObject
@synthesize aString;
@synthesize aDate;
@synthesize aPrimitive;
- (void)getTheTypesOfMyProperties {
unsigned int count;
objc_property_t* props = class_copyPropertyList([self class], &count);
for (int i = 0; i < count; i++) {
objc_property_t property = props[i];
// Here I can easy get the name or value
const char * name = property_getName(property);
// But is there any magic function that can tell me the type?
// the property can be nil at this time
Class cls = magicFunction(property);
}
free(props);
}
@end