如何使用扩展名设置viewController的搜索栏的委托?

IOS*_*Dev 7 iphone cocoa-touch objective-c ios swift2

我创建了导航自定义类,我想装饰它,我拿了NavDecoration.swift类并声明了下面代码中显示的扩展,我在这个函数中添加了搜索条形码,我想在这个扩展中设置搜索栏代理但是它的给定错误不能指定类型'UIViewController'来键入'UISearchBarDelegate

 extension UINavigationController {
 func makeBlackNavigationbar (viewController: UIViewController, animated: Bool) {

 viewController.navigationController?.navigationBar.backgroundColor? = UIColor.blackColor()
    let add = UIBarButtonItem(barButtonSystemItem: .Add, target: viewController, action: "addTapped")
    let play = UIBarButtonItem(title: "Play", style: .Plain, target: viewController, action: "addTapped")
   viewController.navigationItem.rightBarButtonItems = [add, play]

    let left = UIBarButtonItem(barButtonSystemItem: .Add, target: viewController, action: "addTapped")
    viewController.navigationItem.leftBarButtonItems = [left]

       let searchBar = UISearchBar(frame: CGRectZero)
        searchBar.placeholder = "Search"
        searchBar.delegate = viewController
        viewController.navigationItem.titleView = searchBar
}}
Run Code Online (Sandbox Code Playgroud)

IOS*_*Dev 1

**我只更改了几行代码就完成了**

  extension UIViewController : UISearchBarDelegate {

func makeBlackNavigationbar (viewController: UIViewController, animated: Bool) {

    viewController.navigationController?.navigationBar.backgroundColor? = UIColor.blackColor()
    let add = UIBarButtonItem(barButtonSystemItem: .Add, target: viewController, action: "addTapped")
    let play = UIBarButtonItem(title: "Play", style: .Plain, target: viewController, action: "addTapped")
    viewController.navigationItem.rightBarButtonItems = [add, play]
    let left = UIBarButtonItem(barButtonSystemItem: .Add, target: viewController, action: "addTapped")
    viewController.navigationItem.leftBarButtonItems = [left]

       let searchBar = UISearchBar(frame: CGRectZero)
        searchBar.placeholder = "Search"
        searchBar.delegate = viewController
        viewController.navigationItem.titleView = searchBar
}}
Run Code Online (Sandbox Code Playgroud)