我有一个协议及其相应的扩展,看起来像这样:
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
方法仅适用于确认UIViewController
AND的类型,那么它将非常简洁HelpViewControllerDelegate
.
像这样的东西:
extension HelpActionManageable where Self == ItemType
这不起作用.我怎样才能在Swift中实现这一目标?