title: Encode '+' using URLComponents in Swift
body: <p>This is how I add query params to a base URL:</p>
  
  <pre><code>let baseURL: URL = ...
  let queryParams: [AnyHashable: Any] = ...
  var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false)
  components?.queryItems = queryParams.map { URLQueryItem(name: $0, value: "\($1)") }
  let finalURL = components?.url
  </code></pre>
  
  <p>The problem emerges when one of the values contains a <code>+</code> symbol. For some reason it's not encoded to <code>%2B</code> in the final URL, instead, it stays <code>+</code>. If I do encoding myself and pass <code>%2B</code>, <code>NSURL</code> encodes <code>%</code> and the 'plus' becomes <code>%252B</code>.</p>
  
  <p>The question is how can I have <code>%2B</code> in the instance of <code>NSURL</code>?</p>
  
  <p>P.S. I know, I wouldn't even have this problem if I constructed a query string myself and then simply pass a result to the <code>NSURL</code>'s constructor <code>init?(string:)</code>.</p>