Forçado a transmitir, mesmo se o protocolo exigir um determinado tipo
Eu tenho o seguinte código:
import UIKit
protocol Fooable: class where Self: UIViewController {
func foo()
}
class SampleViewController: UIViewController, Fooable {
func foo() {
print("foo")
}
}
let vc1: Fooable = SampleViewController()
let vc2: Fooable = SampleViewController()
// vc1.show(vc2, sender: nil) - error: Value of type 'Fooable' has no member 'show'
// (vc1 as! UIViewController).show(vc2, sender: nil) - error: Cannot convert value of type 'Fooable' to expected argument type 'UIViewController'
(vc1 as! UIViewController).show((vc2 as! UIViewController), sender: nil)
linhas comentadas não são compiladas.
Por quê sou forçado a converter objeto de tipo de protocolo paraUIViewController
mesmo seFooable
requer que os tipos que estejam em conformidade herdemUIViewController
?