是否有可能在Objective-C Generics - Xcode 7+中内省数组的类型

Log*_*gan 6 generics introspection objective-c objective-c-runtime ios

我使用它来获取属性名称的类:

- (Class)gm_classForPropertyName:(NSString *)propertyName {
    objc_property_t prop = class_getProperty([self class], propertyName.UTF8String);
    const char * attr = property_getAttributes(prop);
    NSString *attributes = [NSString stringWithUTF8String:attr];
    NSArray *components = [attributes componentsSeparatedByString:@"\""];
    Class propertyClass;
    for (NSString *component in components) {
        Class class = NSClassFromString(component);
        if (class) {
            propertyClass = class;
            break;
        } else {
            class = swiftClassMapping[component];
            if (class) {
                propertyClass = class;
                break;
            }
        }
    }
    return propertyClass;
}
Run Code Online (Sandbox Code Playgroud)

但这是重要的部分:

    objc_property_t prop = class_getProperty([self class], propertyName.UTF8String);
    const char * attr = property_getAttributes(prop);
    NSString *attributes = [NSString stringWithUTF8String:attr];
Run Code Online (Sandbox Code Playgroud)

当我记录时attributes,它仍然看起来像一个无类型的NSArray作为字符串.有没有办法反省类的类型?

T @家 "的NSArray",&,N,V_children

TL;博士

上这堂课:

@interface SomeClass : NSObject <GenomeObject>
@property (strong, nonatomic) NSArray<SomeOtherClass *> *children;
@end
Run Code Online (Sandbox Code Playgroud)

给定类SomeClass,属性名称children有没有办法让我找到children一个SomeOtherClass类型对象的数组?

Tim*_*Tim 5

根据WWDC关于此功能的讨论,它是使用类型擦除实现的.这意味着有关泛型的信息在编译期间被删除,而不是在运行时出现.

这是相关视频:https://developer.apple.com/videos/wwdc/2015/?id = 401.在lightweight generics讨论开始于约22分钟.在27:20他们解释说它是使用类型擦除实现的.