title: Swift - cannot call selector.. why?
body: <p>OK this is rather odd to me, can someone explain to me why <code>handleDismiss</code> can only be called one way?</p>
  
  <p>consider the following:  </p>
  
  <pre><code>import UIKit
  class MenuLanucher: NSObject, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout
  {
  
      //[...] stuff
  
      let menuItems: [MenuCellSetting] = {
         return [
             MenuCellSetting(name: "Exit Application", imageName: "hamburger", ontap: {
                 print("it is exit")
                 MenuLanucher.handleDismiss() //&lt;-- 2. this is illegal: 'instance member 'handleDismiss' cannot be used on type 'MenuLanucher'; did you mean to use a value of this type instead?'
             }),
              MenuCellSetting(name: "Create", imageName: "gear", ontap: {
                 print("it is job")
                 self?.HandleDismiss() //&lt;-- 2. illegal : 'Cannot use optional chaining on non-optional value of type '(MenuLanucher) -&gt; () -&gt; (MenuLanucher)''
             }),
             MenuCellSetting(name: "Cancel", imageName: "gear", ontap: {
                 print("it is nothing")
                 perform(#selector(MenuLanucher.handleDismiss)) //&lt;-- 3. crashes on run time 'unrecognized selector sent to class'
             })
          ]
        }()
  
       //[...] yet
  
       func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
           menuItems[indexPath.item].ontap()
           handleDismiss() //&lt;--1. works
       }
  
        @objc func handleDismiss(){
           print("dismiss works")
       }
  }
  
  class MenuCellSetting: NSObject {
       let name: String
      let imageName: String
      let ontap: ()-&gt;Void
      init(name: String, imageName: String, ontap: @escaping ()-&gt;Void){
           self.name = name
           self.imageName = imageName
           self.ontap = ontap
       }
   }
  </code></pre>
  
  <p>in this example</p>
  
  <ol>
  <li>fails: at runtime saying 'unrecognized selector sent to class' </li>
  <li>fails: at compile saying 'instance member 'handleDismiss' cannot be used on type 'MenuLanucher'; did you mean to use a value of this type instead?'</li>
  <li>works</li>
  </ol>
  
  <p>my question is: why is the difference? what is going on?</p>
  
  <p><strong>EDIT: self.?handleDismiss() also fails (see image)</strong></p>
  
  <p><a href="https://i.stack.imgur.com/04Z7M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/04Z7M.png" alt="enter image description here"></a></p>