你能在Swift中转换为元类型吗?看起来你应该能够(毕竟你可以从Metatypes实例化对象).
以下不起作用:
class Super {} class A : Super {} let superA:Super = A() let subType = superA.dynamicType let afterCast = superA as subType //Compiler error: "use of undeclared type 'subType'"
有谁知道这样做的正确方法?
编辑:
正如newacct指出的那样,直到运行时才明白.dynamicType的结果,因此编译时转换为.dynamicType的结果是没有意义的.
所以答案是:"你不能"(并且没有充分的理由去尝试).