Swift: Using protocol extension results in "unrecognized selector sent to instance"
<p>I'm trying to add a on-tap functionality to all UIViewControllers where they conform to protocol <code>MyProtocol</code>.</p>

<p>Below is how i'm doing it:</p>

<pre><code>import UIKit

protocol MyProtocol: class{
    var foo: String? {get set}
    func bar()
}


extension MyProtocol where Self: UIViewController {
    func bar() {
        print(foo)
    }
}


class TestViewController: UIViewController, MyProtocol{
    var foo: String?

    override func viewDidLoad() {
        super.viewDidLoad()

        foo = "testing"
        let tapGesture = UITapGestureRecognizer(target: self, action: "bar")
}
</code></pre>

<p>Which results in following when screen is tapped: </p>

<p><code>Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:  unrecognized selector sent to instance</code></p>

<p>I understand the error but don't know how to fix it. Can anyone suggest how this can be done?</p>