Xcode 7 包含一个 Objective-C 变体,您可以在其中为 (homogenous) NSArray
定义类型提示返回值和属性,定义为 NSArray<UIImage*>
.
我想使用此功能重写我的 JSON 反序列化器类(它需要此类类型提示 - 之前我通过向具有同质数组作为属性的类添加 -(Class)jsonHintForKey:(NSString*)key
解决了这个问题。)
您知道我是否(如果可以,如何)在运行时使用 Objective-C 运行时获取此新类型提示的类?
最佳答案
Xcode 7 中引入的轻量级泛型只是编译时提示以帮助编译器发出警告,但在运行时你会得到相同的旧行为,你的变量只是 的
s.NSArray
id
来源:WWDC '15 "Swift and Objective-C Interoperability" session
参见 the transcript of the talk :
So the entire lightweight generics feature is based on a type erasure model. Which means that the compiler has all of this rich static type information but it erases that information when generating code.
关于ios - 我如何找出 Objective-C 泛型类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30866197/