7
을 부여 필요하더라도, 캐스팅 강제 :프로토콜은 내가 다음 코드 한 유형
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)
컴파일하지 않는 선 댓글을 달았습니다.
내가 그것을 준수 유형UIViewController
에서 상속,
Fooable
프로토콜이 필요
UIViewController
경우에도에 프로토콜 유형의 개체를 캐스팅 강요하고 왜
?