title: How to encode special character like ’ (NSWindowsCP1250StringEncoding) in Swift2
body: <p>As in <code>Swift2</code> <code>stringByAddingPercentEscapesUsingEncoding()</code> is deprecated instead of <code>stringByAddingPercentEncodingWithAllowedCharacters()</code> is used.</p>
  
  <p>But how to encode the especial character like ' % &amp; in <code>swift2</code>   </p>
  
  <p>For example in <code>iOS8</code>(swift1.2) i used following code for encoding</p>
  
  <pre><code>NSURL(string: "myurl.php?deviceName=name’phone".stringByAddingPercentEscapesUsingEncoding(NSWindowsCP1250StringEncoding)!)
  </code></pre>
  
  <p>it work fine i.e. on server it decode correctly.</p>
  
  <p>But in <code>iOS9</code>(Swift2.0) i used following code </p>
  
  <pre><code>NSURL(string: "myurl.php?deviceName=name ’phone".stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLFragmentAllowedCharacterSet())!)
  </code></pre>
  
  <p>It will not decode properly.<br>
  please tell me how i can encode special charater in swift2.0 ?</p>
  
  <p><strong>EDIT :</strong>
  Eric D answer is right but when i encode below <code>stringURL</code>  it will not encode properly.
  Why?</p>
  
  <pre><code>let stringURL = "https://my.server.com/login.php?e=email&amp;dn=my’s iPad&amp;d=5&amp;er=D550772E-34BB-4DCB-89C9-E746FAD83D24&amp;tz=330"
          print(stringURL)
          let charSet = NSCharacterSet.URLPathAllowedCharacterSet()
          let encoded = stringURL.stringByAddingPercentEncodingWithAllowedCharacters(charSet)!
  
          let url = NSURL(string: encoded.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLFragmentAllowedCharacterSet())!)!
  
          print(url) //https%253A//my.server.com/login.php%253Fe=email&amp;dn=my%25E2%2580%2599s%2520iPad&amp;d=5&amp;er=D550772E-34BB-4DCB-89C9-E746FAD83D ... 4&amp;tz=330
  </code></pre>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>How to encode <strong>NSWindowsCP1250StringEncoding</strong> in <strong>swift2.0</strong> ?</p>