I am creating an app that is essentially a webview. It uses custom, proprietary fonts that cannot be used in a regular webapp, hence the app wrapper.
It works fine for most purposes but I wanted to check if a URL request loaded properly, to send a 'page not found' message or some such when a bad URL is given or the URL fails to load. For this I believe I need a delegate.
Problem: every time I try to create a delegate (despite trying a few ways I've seen in examples) the app just crashes on load.
(By the way: if I create the webview programmatically rather than in the storyboard, the custom fonts do not load, which for my purposes is a failure of the main requirement. Please keep this in mind if you have a solution)
Code:
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
@IBOutlet var containerView: UIView!
var screenEdgeRecognizer: UIScreenEdgePanGestureRecognizer!
//var currentRadius:CGFloat = 0.0
@IBOutlet var webView: WKWebView!
override func viewDidLoad() {
    super.viewDidLoad()
    screenEdgeRecognizer = UIScreenEdgePanGestureRecognizer(target: self,
        action: #selector(ViewController.goBack(_:)))
    screenEdgeRecognizer.edges = .Left
    view.addGestureRecognizer(screenEdgeRecognizer)
    // *** This line commented out to prevent app from crashing!
    //self.webView.navigationDelegate = self
    webView.hidden = false;
    // this allows the UIWebView box to your background color seamlessly.
    webView.opaque = false;
    // Do any additional setup after loading the view, typically from a nib.
    let url = NSURL (string: "http://localhost/web_app/mobile_login.php");
    let requestObj = NSURLRequest(URL: url!);
    //let localfilePath = NSBundle.mainBundle().URLForResource("home", withExtension: "html");
    //let requestObj = NSURLRequest(URL: localfilePath!);
    webView.loadRequest(requestObj);
    //webView.allowsBackForwardNavigationGestures = true;
}
// **** This code I hope to use but I think requires a delegate in order to work
func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: NSError) {
    let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .Alert)
    alert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil))
    presentViewController(alert, animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
override func preferredStatusBarStyle() -> UIStatusBarStyle {
    //LightContent
    return UIStatusBarStyle.LightContent
    //Default
    //return UIStatusBarStyle.Default
}
func goBack(sender: UIScreenEdgePanGestureRecognizer) {
    //
    self.webView.goBack()
}
}
Many thanks for advice.