0

Currently i am using the following way to encode the url

urlAndMethod.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())!

After encoding

http://103.50.154.52:8383/api/master/insta-list?category=Postpaid%20Mobile%20CDMA%20&%20Landline

How do i handle the special characters including '&'

rmaddy
  • 307,833
  • 40
  • 508
  • 550
Cloy
  • 2,101
  • 22
  • 31
  • Possible duplicate of https://stackoverflow.com/questions/705448/iphone-sdk-issue-with-ampersand-in-the-url-string – Kapil G Jul 24 '17 at 05:43

1 Answers1

2

You can use .urlHostAllowed characterset.

let escapedString = someString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
MjZac
  • 3,303
  • 1
  • 20
  • 27