respondsToSelector can't recognize Selector with more than one parameters in Swift : <p>I have a <code>protocol</code> with some <code>optional</code> functions.  My goal is to check if a delegate function is implemented by the delegate object, if yes execute it, otherwise do some default stuff.</p>

<p>I am using <code>respondsToSelector</code> for this purpose, it works fine for functions that with none or only one parameters, but doesn't work for two parameters.</p>

<p>Could anyone help? Thanks in advance.</p>

<p>Note that all the functions have been implemented by the delegate object, here is my code:</p>

<pre><code>@objc protocol ViewControllerDelegate: NSObjectProtocol {

    optional func doSomethingWithoutParams()

    optional func doSomethingWithOneParam(controller: ViewController)

    optional func doSomethingWithTwoParams(controller: ViewController, secondParam: String)
}

class ViewController: UIViewController {

    weak var delegate: ViewControllerDelegate?

    @IBAction func onButtonClicked(sender: AnyObject){

        if (delegate != nil &amp;&amp; delegate!.respondsToSelector(Selector("doSomethingWithoutParams"))) {

            // Entered here

        }
        else{
            NSLog("doSomethingWithoutParams is not implemented")
        }

        if (delegate != nil &amp;&amp; delegate!.respondsToSelector(Selector("doSomethingWithOneParam:"))) {

            // Entered here

        }
        else{
            NSLog("doSomethingWithOneParam is not implemented")
        }

        if (delegate != nil &amp;&amp; delegate!.respondsToSelector(Selector("doSomethingWithTwoParams::"))) {
            NSLog("doSomethingWithTwoParams is implemented")
        }
        else{

            // Entered here

            NSLog("doSomethingWithTwoParams is not implemented")
        }
    }
}
</code></pre>
