title: Swift: How to put current URL from UIWebView into UITextField?
body: <p>(XCode 6.3.2, Swift 1.2)  I simply want to put the URL of the loaded webpage of the UIWebView into an UITextField. The solutions which I found <a href="https://stackoverflow.com/questions/27549661/swift-why-i-cant-get-the-current-url-loaded-in-uiwebview">here</a> doesn't work for me.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>@IBOutlet weak var addressBar: UITextField!
  @IBOutlet weak var webView: UIWebView!
  
  //some more code...
  
  func webViewDidFinishLoad(webView : UIWebView) {
     self.addressBar.text = (self.webView.request?.URL.absoluteString)!
  }
  </code></pre>
  
  <p>Swift Compiler Error: <em>Value of optional type 'NSURL?' not unwrapped; did you mean to use '!' or '?'?</em></p>
  
  <p>Any ideas or hints would be very appreciated.
  Thanks.</p>
  
  <p><strong>EDIT:</strong><br>
  The answer from <em>Airspeed Velocity</em> works for me (see working code below). However I  recognized that sometimes the loaded URL isn't correctly written back to the UITextField.<br>
  It's reproducible for example on Vimeo.
  When I click on a video link on vimeo.com the URL should change to something like: <a href="https://vimeo.com/105060039" rel="nofollow noreferrer">https://vimeo.com/105060039</a><br>
  On mobile Safari this works fine but not on the UIWebView. To the URL "<a href="https://vimeo.com/" rel="nofollow noreferrer">https://vimeo.com/</a>" the video number isn't added.<br>
  What I'm doing wrong? Is there an other possibility to get the current URL?</p>
  
  <pre><code>@IBOutlet weak var addressBar: UITextField!
  @IBOutlet weak var webView: UIWebView!
  
  //some more code...
  
  func webViewDidFinishLoad(webView: UIWebView) {
     addressBar.text = webView.request?.URL?.absoluteString
  }
  </code></pre>