title: How do I change the user agent in my WebView using Swift 4.2?
body: <p>I'm struggling with changing the user agent on my project using the latest Xcode version with swift 4.2 .</p>
  
  <p>I want to pretend that I'm a Mac visiting a specific website.
  Please edit this code and post it in the comments</p>
  
  <p>Here's my code so far.</p>
  
  <pre><code>class ViewController: UIViewController {
      @IBOutlet weak var webview: WKWebView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          let userAgent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36 Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10"
          let myURL = NSURL(string: "http://website.com")
          let myURLRequest:NSURLRequest = URLRequest(url: myURL! as URL) as NSURLRequest
          webview.load(myURLRequest as URLRequest)
          myURLRequest.setValue(userAgent, forKey: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36")
  
          webview.load(URLRequest(url: myURL! as URL))
      }
  }
  </code></pre>
  
  <p>If I build it I receive this error:</p>
  
  <p>![Error][2].</p>