title: Send data to WKWebView
body: <p>I am creating a View which displays a local webpage which also has styles and JavaScript (Essentially a hybrid native application) and I am using a WKWebView. </p>
  
  <p>I know how to send data from the JavaScript to the native code but it is not clear how to do it the reverse way. I am wanting to send a JSON Object that is fetched using native iOS code to my MKWebView.</p>
  
  <p>I am getting the following error</p>
  
  <pre><code>Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo=0x7bfb3c30 {NSLocalizedDescription=A JavaScript exception occurred}
      nil
  </code></pre>
  
  <p>Below is my code.</p>
  
  <pre><code>//
  //  WebViewController.swift
  //
  //  Created by Adam Bulmer on 09/03/2015.
  //  Copyright (c) 2015 Adam Bulmer. All rights reserved.
  //
  
  import Foundation
  import WebKit
  
  class WebViewController: BaseViewController, WKScriptMessageHandler, WKNavigationDelegate {
  
      @IBOutlet var containerView : UIView! = nil
      var webView: WKWebView!
  
      override func loadView() {
  
          super.loadView()
  
          var config = WKWebViewConfiguration();
          var contentController = WKUserContentController();
  
          var userScript = WKUserScript(
              source: "bootstrap()",
              injectionTime: WKUserScriptInjectionTime.AtDocumentEnd,
              forMainFrameOnly: true
          )
  
          contentController.addUserScript(userScript)
          config.userContentController = contentController;
  
  
          self.webView = WKWebView(frame:self.view.frame, configuration: config)
          self.webView.navigationDelegate = self;
  
          self.view = self.webView!
  
      }
  
      override func viewDidLoad() {
  
          super.viewDidLoad()
  
          var path = NSBundle.mainBundle().pathForResource(webViewName(),
              ofType: "html");
  
          var url = NSURL(fileURLWithPath: path!);
          var request = NSURLRequest(URL: url!);
  
          self.webView!.loadRequest(request);
  
      }
  
      func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {
  
          var param = "Hello World";
          var exec_template = "test(\(param)');";
  
          self.webView!.evaluateJavaScript(exec_template, completionHandler: { (test, error) -&gt; Void in
              println(error);
              println(test);
          })
  
      }
  
      func webViewName() -&gt; String {
          return "";
      }
  
  // MARK: WKScriptMessageHandler callback
  // Delegate callback for when scripts sends message
  
      func userContentController(userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) {
  
      }
  
  }
  </code></pre>