一般说明:

我需要能够在我所做的UIViewController和UITableViewController的2个子类的配置器类实例中使用,但我需要检查它是否是这两个子类中的一个,而不仅仅是一般类,所以在方法定义中我我期待这种类型2(它们都符合通用协议) .

深入:

我有一个协议

protocol UIViewControllerNavigationBarConfig
{
    var doneButtonTitle : String? { get set }

    func configureNavigationBar()

    func disableNavigationBarConfig()
}

我有一个UIViewController(ViewControllerWithNavigationBarConfig)的子类,它采用这个协议,也是UITableViewController(TableControllerWithNavBarConfig)的子类,它也采用这个协议 .

现在,我有一个配置器类,知道如何自定义我的控制器与这里的近似定义(我jus没有包括其他函数和func体):

class ControllerConfigurator<NavigationBarConfigurable : UIViewController where NavigationBarConfigurable : UIViewControllerNavigationBarConfig>
{
    class func configureNavigationBarWithInfo(controller: NavigationBarConfigurable)
}

问题是......如果我在类定义(ControllerConfigurator)中定义类型约束NavigationBarConfigurable,我无法对任何子类使用“configureNavigationBarWithInfo”,因为每次我尝试这样做时,例如:

class SelectQuestionsController: TableControllerWithNavBarConfig
{
    override func viewWillAppear(animated: Bool)
    {
        ControllerConfigurator.configureNavigationBarWithInfo(self)
    }
}

我收到“类型UIViewController不符合协议”,这当然是合乎逻辑的,但我的想法是“我的两个子类都将UIViewController作为超类,所以如果我将条件设置为UIViewController并符合该协议,那么应该适合我的机器人子类“ .

如何定义类型约束以使其起作用?