title: How to pass url as url parameter in swift?
body: <p>I have to pass url as parameter for another url. For example </p>
  
  <p><a href="https://www.host1.com?returnURL=https://www.host2.com/path?queryparamater1=value&amp;queryparameter2=value" rel="nofollow noreferrer">https://www.host1.com?returnURL=https://www.host2.com/path?queryparamater1=value&amp;queryparameter2=value</a></p>
  
  <pre><code>
  var returnUrlComponents = URLComponents()
          returnUrlComponents.scheme = "https"
          returnUrlComponents.host = "www.host.com"
          returnUrlComponents.path = "/path1"
          let queryItem1 = URLQueryItem(name: "param1", value: "value1")
          let queryItem2 = URLQueryItem(name: "redirect_uri", value: "test://result")
          returnUrlComponents.queryItems = [queryItem1, queryItem2]
          var urlComponents = URLComponents()
  
          urlComponents.scheme = "https"
          urlComponents.host = "www.anotherhost.com"
          urlComponents.path = "/path2"
          urlComponents.queryItems = [URLQueryItem(name: "returnURL", value: returnUrlComponents.url?.absoluteString)]
          print(urlComponents.url?.absoluteString)
  
  </code></pre>
  
  <p>The output is this - <a href="https://www.anotherhost.com/path2?returnURL=https://www.host.com/path1?param1%3Dvalue1%26redirect_uri%3Dtest://result" rel="nofollow noreferrer">https://www.anotherhost.com/path2?returnURL=https://www.host.com/path1?param1%3Dvalue1%26redirect_uri%3Dtest://result</a></p>
  
  <p>Expected output - <a href="https://www.anotherhost.com/path2?returnURL=https%3A%2F%2Fwww.host.com%2Fpath1%3Fparam1%3Dvalue1%26redirect_uri%3Dtest%3A%2F%2Fresult" rel="nofollow noreferrer">https://www.anotherhost.com/path2?returnURL=https%3A%2F%2Fwww.host.com%2Fpath1%3Fparam1%3Dvalue1%26redirect_uri%3Dtest%3A%2F%2Fresult</a></p>