 import WebKit
 
 public class WebViewObserver: NSObject {
+    enum KeyPath: String {
+        case Title = "title"
+        case URL = "URL"
+        case EstimatedProgress = "estimatedProgress"
+        case CanGoBack = "canGoBack"
+        case CanGoForward = "canGoForward"
+        case HasOnlySecureContent = "hasOnlySecureContent"
+        case Loading = "loading"
+    }
     let webView: WKWebView
     private let context = UnsafeMutablePointer<Void>()
-    private let observableProperties = ["title", "URL", "estimatedProgress", "canGoBack", "canGoForward", "hasOnlySecureContent", "loading"]
+    private let keyPaths: [KeyPath] = [
+        .Title, .URL, .EstimatedProgress,
+        .CanGoBack, .CanGoForward,
+        .HasOnlySecureContent, .Loading,
+    ]
 
     public var onTitleChanged: String? -> Void = { _ in }
     public var onURLChanged: NSURL? -> Void = { _ in }


    public override func observeValueForKeyPath(keyPath: String?, ofObject: AnyObject?, change: [String: AnyObject]?, context: UnsafeMutablePointer<Void>) {
        if context != self.context { return }

        switch keyPath {
        case "title"?: onTitleChanged(webView.title)
        case "URL"?: onURLChanged(webView.URL)
        case "estimatedProgress"?: onProgressChanged(webView.estimatedProgress)
        case "canGoBack"?: onCanGoBackChanged(webView.canGoBack)
        case "canGoForward"?: onCanGoForwardChanged(webView.canGoForward)
        case "hasOnlySecureContent"?: onHasOnlySecureContentChanged(webView.hasOnlySecureContent)
        case "loading"?: onLoadingStatusChanged(webView.loading)
        default: ()
        }
    }

}

    }

    private func observeProperties() {
        for k in keyPaths {
            webView.addObserver(self, forKeyPath: k.rawValue, options: .New, context: context)
        }
    }

    deinit {
        for k in keyPaths {
            webView.removeObserver(self, forKeyPath: k.rawValue, context: context)
        }
    }

    private func dispatchObserver(keyPath: KeyPath) {
        switch keyPath {
        case .Title: onTitleChanged(webView.title)
        case .URL: onURLChanged(webView.URL)
        case .EstimatedProgress: onProgressChanged(webView.estimatedProgress)
        case .CanGoBack: onCanGoBackChanged(webView.canGoBack)
        case .CanGoForward: onCanGoForwardChanged(webView.canGoForward)
        case .HasOnlySecureContent: onHasOnlySecureContentChanged(webView.hasOnlySecureContent)
        case .Loading: onLoadingStatusChanged(webView.loading)
        }
    }

