title: How to use stringByAddingPercentEncodingWithAllowedCharacters() for a URL in Swift 2.0
body: <p>I was using this, in Swift 1.2</p>
  
  <pre><code>let urlwithPercentEscapes = myurlstring.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
  </code></pre>
  
  <p>This now gives me a warning asking me to use</p>
  
  <pre><code>stringByAddingPercentEncodingWithAllowedCharacters
  </code></pre>
  
  <p>I need to use a <strong>NSCharacterSet</strong> as an argument, but there are so many and I cannot determine what one will give me the same outcome as the previously used method.</p>
  
  <p><strong>An example URL I want to use will be like this</strong></p>
  
  <pre><code>http://www.mapquestapi.com/geocoding/v1/batch?key=YOUR_KEY_HERE&amp;callback=renderBatch&amp;location=Pottsville,PA&amp;location=Red Lion&amp;location=19036&amp;location=1090 N Charlotte St, Lancaster, PA
  </code></pre>
  
  <p>The URL Character Set for encoding seems to contain sets the trim my
  URL. i.e, </p>
  
  <blockquote>
    <p>The path component of a URL is the component immediately following the
    host component (if present). It ends wherever the query or fragment
    component begins. For example, in the URL
    <a href="http://www.example.com/index.php?key1=value1">http://www.example.com/index.php?key1=value1</a>, the path component is
    /index.php.</p>
  </blockquote>
  
  <p>However I don't want to trim any aspect of it.
  When I used my String, for example <code>myurlstring</code> it would fail.</p>
  
  <p>But when used the following, then there were no issues. It encoded the string with some magic and I could get my URL data.</p>
  
  <pre><code>let urlwithPercentEscapes = myurlstring.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
  </code></pre>
  
  <p>As it</p>
  
  <blockquote>
    <p>Returns a representation of the String using a given encoding to
    determine the percent escapes necessary to convert the String into a
    legal URL string</p>
  </blockquote>
  
  <p>Thanks</p>