[英]Swift Protocol for present() function in UIViewController
我想創建一個當前UIViewController.present函數符合的協議(委托)。
因此,例如協議是:
protocol PresentPopupDelegate
{
func doSomething()
func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Swift.Void)?)
}
需要遵守該協議的類是:
class MyViewController:UIViewController, PresentPopupDelegate {
func doSomething()
}
並說我有以下代碼:
let delegate:PresentPopupDelegate
init() {
self.delegate = MyViewController()
}
編譯這將導致警告說
未實現協議“ PresentPopupDelegate”中的方法“ present:animated:completion:”
現在,我假設原因是因為在原始函數中,將完成函數的默認參數設置為“ nil”。 但是,協議不支持默認參數。
因此,我的問題是:我可以(如果可以的話)如何創建UIViewController.present(...)函數可以遵循的協議?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.