title: WKWebview Swift 4 UIProgressBar Doesn't work Xcode 9
body: <p>I am trying to add a progress bar that fills as the WKWebview loads. I have tried using the code below.</p>
  
  <p>import UIKit
  import WebKit
  class GmailViewController: UIViewController, WKUIDelegate, WKNavigationDelegate{</p>
  
  <pre><code>@IBOutlet weak var progressView: UIProgressView!
  @IBOutlet weak var contentView: UIView!
  @IBOutlet weak var webView: WKWebView!
  @IBAction func homeBtn(_ sender: Any) {
       self.performSegue(withIdentifier: "HomeScreen", sender: self)
  }
  override func viewDidLoad() {
      super.viewDidLoad()
      let webConfiguration = WKWebViewConfiguration()
      webConfiguration.websiteDataStore = WKWebsiteDataStore.default()
      let webView = WKWebView(frame: .zero, configuration: webConfiguration)
      webView.navigationDelegate = self
      webView.uiDelegate = self
      self.webView = webView
      if let webView = self.webView
      {
          view.addSubview(webView)
          webView.translatesAutoresizingMaskIntoConstraints = false
          let height = NSLayoutConstraint(item: webView, attribute: .height, relatedBy: .equal, toItem: self.contentView, attribute: .height, multiplier: 1, constant: 0)
          let width = NSLayoutConstraint(item: webView, attribute: .width, relatedBy: .equal, toItem: self.contentView, attribute: .width, multiplier: 1, constant: 0)
          let offset = NSLayoutConstraint(item: webView, attribute: .top, relatedBy: .equal, toItem: self.contentView, attribute: .top, multiplier: 1, constant: 0)
          view.addConstraints([height, width, offset])
      }
      let myURL = URL(string: "https://gmail.com/mail")
      let myRequest = URLRequest(url: myURL!)
      webView.load(myRequest)
      progressView = UIProgressView(progressViewStyle: .default)
      progressView.sizeToFit()
      // Set frame to exact below of navigation bar if available
      progressView.frame = CGRect(x: 0, y: 64, width: self.view.bounds.size.width, height: 20)
      self.view.addSubview(progressView)
      webView.addObserver(self, forKeyPath: #keyPath(WKWebView.estimatedProgress), options: .new, context: nil)
  }
  override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
      if keyPath == "estimatedProgress" {
          print("estimatedProgress")
          progressView.progress = Float(webView.estimatedProgress)
      }}
    }
  </code></pre>
  
  <p>for some strange reason it returns the error on runtime cannot set event for nil.</p>