 
     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: ()
-        }
+        keyPath.flatMap(KeyPath.init).map(dispatchObserver)
     }
 
 }

import WebKit

public class WebViewObserver: NSObject {
    let webView: WKWebView
    private let context = UnsafeMutablePointer<Void>()
    private let observableProperties = ["title", "URL", "estimatedProgress", "canGoBack", "canGoForward", "hasOnlySecureContent", "loading"]

    public var onTitleChanged: String? -> Void = { _ in }
    public var onURLChanged: NSURL? -> Void = { _ in }

    }

    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)
        }
    }

