title: How can I send data from javascript to swift?
body: <p>I am doing an iOS hybrid app using swift and HTML/Javascript. IN Android I can use web view:</p>
  
  <pre><code> WebSettings settings = web view.getSettings();
   settings.setJavaScriptEnabled(true);
   webView.addJavascriptInterface(this,"Book");
  webView.loadUrl("http://example.com/test.html");
  </code></pre>
  
  <p>public void back() {
  ....
  }</p>
  
  <p>and in test.html there is a javascript when you click a button you run javascript code: Book.back(); so the control will go from javascript to android to run the function back(). How can I do something similar in swift ?</p>
  
  <pre><code>import WebKit
  ....
          let url = Bundle.main.url(forResource: "test", withExtension: "html")!
          webView.loadFileURL(url, allowingReadAccessTo: url)
          let request = URLRequest(url: url)
          webView.load(request)
  </code></pre>