1
我試圖在swift中打開一個類型。我沒有試圖打開對象實例的類型,我試圖打開實際的類型本身。例如:打開Any.Type
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的'Type Casting'文檔,可能不夠徹底,因爲我看不到在這裏應用它的方法。