title: Open UIWebView Links In Safari
body: <p>I have an iOS app using Swift 3. I have a uiwebview in this app. Whenever a user clicks on a link in the webview, it opens up inside the webview. I need it to where the links open up inside the Safari app on the iPhone. Here's the code:</p>
  
  <pre><code>class VideosViewController: UIViewController {
  
      @IBOutlet var webView: UIWebView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          var URL = NSURL(string: "http://example.com")
  
          webView.loadRequest(NSURLRequest(url: URL! as URL) as URLRequest)
  
  
      }
  
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  }
  </code></pre>
  
  <p>Can you please give me some code that I can enter? I'm new at coding, so thanks a lot.</p>
  
  <p><strong>UPDATE:</strong> Thanks to an answer I got some code, but the links are still not opening in Safari. Here's the code so far...</p>
  
  <pre><code>class VideosViewController : UIViewController, UIWebViewDelegate {
  
  @IBOutlet weak var webView : UIWebView!
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      guard let url = URL(string: "http://example.com") else { return }
  
      let request = URLRequest(url: url)
      webView.loadRequest(request)
  
  }
  
  func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -&gt; Bool {
  
      if navigationType == .linkClicked {
  
          guard let url = request.url else { return true }
          UIApplication.shared.open(url, options: [:], completionHandler: nil)
          return false
      }
      return true
  }
  </code></pre>
  
  <p>}</p>