0
我有兩個問題迅速
1.指定多個類型的委託
2.指定類型的委託如何爲委託參考指定多個類型?
id<MyProtocol, MyAnotherProtocol> delegate;
UIViewController<MyProtocol> *delegate;
如何轉換這兩個線迅速?
我搜索了互聯網,並試圖查看庫代碼,以便我可以得到提示,但沒有得到任何東西。
我有兩個問題迅速
1.指定多個類型的委託
2.指定類型的委託如何爲委託參考指定多個類型?
id<MyProtocol, MyAnotherProtocol> delegate;
UIViewController<MyProtocol> *delegate;
如何轉換這兩個線迅速?
我搜索了互聯網,並試圖查看庫代碼,以便我可以得到提示,但沒有得到任何東西。
使用:
var delegate: protocol<MyProtocol, MyAnotherProtocol>
對於第二個你可以使用:
var delegate: MyProtocol
您可以使用protocol composition
在單個名稱如下組合多個協議。
// Protocol Composition!!
typealias MyCompositeProtocol = protocol< MyProtocol, MyAnotherProtocol >
然後你就可以使用名稱MyCompositeProtocol
,而不是指定多個名稱。
像下面,
class DetailsViewController: UIViewController, MyCompositeProtocol {
var myDelegate : MyCompositeProtocol?
}
第二個是不完全型的'UIViewController'實現'MyProtocol'。它是任何實現「MyProtocol」的類的參考 –