title: How to pass functions when making UIButton programmatically in Swift
body: <p>I would like to pass a function as parameter, and use it in the UITableView extension. In the function named 'setEmptyView', I made UIButton programmatically, and added some target action. Here's what I've done so far.</p>
  <pre><code>extension UITableView {
      func setEmptyView(message: String, actionButtonClosure: @escaping () -&gt; Void) {
          let emptyView = UIView()
          let messageLabel = UILabel()
          let button = UIButton()
  
          // adding subview and making constraints codes....
  
          button.addTarget(self, action: #selector(buttonAction(_:)), for: .touchUpInside)
      }
      @objc func buttonAction (_ sender: UIButton!) {
          actionButtonClosure()    &lt;---- error
      }
  }
  
  class ViewController: UITableViewDataSource, UITableViewDelegate {
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          if count == 0 {
              let message = &quot;Here is placeholder for this table&quot;
              tableView.setEmptyView(message: message, buttonTitle: &quot;see more&quot;) { [self] in
                  goToMenu()
              }
          }
          return count
      }
      func goToMenu() {
          // move to next VC
      }
  </code></pre>
  <p>Unfortunately 'actionButtonClosure' function in parameter cannot be accessible because it's two different function. I also tried .addAction() to the button, but it is only available since iOS14. What would you suggest to do here? How can I pass function parameter and use it as button action?</p>