You can workaround it by doing
var cat = obj as Cat as Animal
but this workaround is almost useless... because you need to know the type of obj
first
Edit:
As @newacct point out, it is not bug, see his answer for more information
xcrun swift
Welcome to Swift! Type :help for assistance.
1>
2> @objc protocol Animal {
3. func walk()
4. }
@objc class Cat: Animal {
func walk() {}
init() { }
}
var obj: AnyObject = Cat()
var cat = obj as Animal
5>
6> @objc class Cat: Animal {
7. func walk() {}
8.
9. init() { }
10. }
11>
12> var obj: AnyObject = Cat()
obj: Cat = {}
13>
14> var cat = obj as Animal
cat: Cat = {}
15>
Animal
protocol need @objc
attribute and Cat
need to be @objc class
.