【发布时间】:2016-03-26 05:57:43
【问题描述】:
我正在尝试快速打开一种类型。我不是要打开对象实例的类型,而是要打开实际类型本身。例如:
let t: Any.Type = Int.self
switch t {
case is Int:
print("int")
default:
print("other")
}
我希望这会打印“int”,但它属于默认情况。
我可以用 if 语句来完成想要的结果,例如,
if t == Int.self
{
print("t is an int")
}
但我希望有一种方法可以通过开关来做到这一点。我已经阅读了 Apple 的“类型转换”文档,可能还不够彻底,因为我看不到在此处应用它的方法。
【问题讨论】:
标签: swift