How can I find out the Objective-C generics type?

前端 未结 2 1470
野性不改
野性不改 2020-12-09 17:01

Xcode 7 contains an Objective-C variant, where you can define a type-hint for (homogenous) NSArray return values and properties, defined such as NSArray&l

相关标签:
2条回答
  • 2020-12-09 17:44

    The lightweight generics introduced in Xcode 7 are just compile time hints to help the compiler raise warnings, but at run time you get the same old behavior with your variable being just NSArrays of ids.

    Source: WWDC '15 "Swift and Objective-C Interoperability" session

    See 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.

    0 讨论(0)
  • 2020-12-09 17:48

    It is not possible to do that.

    Generics were introduced in objective-c to improve the bridge between swift and objective-c. The advantage it gives to objective-c is only useful at compile time, and I that information is lost at runtime.

    0 讨论(0)
提交回复
热议问题