当前位置:  开发笔记 > 编程语言 > 正文

如何在Swift中对两种类型进行协议扩展约束

如何解决《如何在Swift中对两种类型进行协议扩展约束》经验,为你挑选了0个好方法。

我有一个协议及其相应的扩展,看起来像这样:

import Foundation


protocol HelpActionManageable {
    typealias ItemType : UIViewController,HelpViewControllerDelegate
    var viewController : ItemType {
        get
    }
}

extension HelpActionManageable  {
    func presentHelpViewController() {
        let helpViewController = HelpViewController(nibName: HelpViewController.nibName(), bundle: nil)
        viewController.presentViewController(helpViewController, animated: true, completion:nil)
        helpViewController.delegate = viewController
    }
    func dismissSuccessfulHelpViewController(helpViewController:HelpViewController) {
        helpViewController.dismissViewControllerAnimated(true) { () -> Void  in
            self.viewController.showAlertControllerWithTitle(GlobalConstants.Strings.SUCCESS, message: GlobalConstants.Strings.VALUABLE_FEEDBACK, actions: [], dismissingActionTitle: GlobalConstants.Strings.OK, dismissBlock: nil)
        }
    }
}

所以,在随机视图控制器中确认了这个协议,我做的是这样的:

class RandomViewController : UIViewController, HelpViewControllerDelegate,HelpActionManageable {
    //HelpViewControllerDelegate methods...
    var viewController : RandomViewController {
        return self
    }
}

这样可以正常工作,但如果扩展HelpActionManageable方法仅适用于确认UIViewControllerAND的类型,那么它将非常简洁HelpViewControllerDelegate.

像这样的东西:

extension HelpActionManageable where Self == ItemType

这不起作用.我怎样才能在Swift中实现这一目标?

推荐阅读
Life一切安好
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有