I have a protocol and its corresponding extension, which looks something like this:
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) } } }
So, in the arbitrary view controller that confirms this protocol, I am doing something like this:
class RandomViewController : UIViewController, HelpViewControllerDelegate,HelpActionManageable {
This works fine, but it would be very neat if the HelpActionManageable extension HelpActionManageable were only available for types that confirm the value of UIViewController AND HelpViewControllerDelegate .
Something like that:
extension HelpActionManageable where Self == ItemType
This does not work. How can I achieve this in Swift?
source share