【发布时间】:2015-04-08 16:38:50
【问题描述】:
我有以下代码。如何解决最后一行的错误?
protocol Animal {
func walk()
}
struct Cat: Animal {
func walk() {}
init() { }
}
var obj: Any = Cat()
var cat = obj as Animal // ERROR: cannot downcast from Any to unrelated type Animal
【问题讨论】:
-
re:你在最后一行看到的错误,它显示为
// ERROR: cannot downcast from Any to unrelated type Animal,不是Cat,对吧?