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
  • 314,917
  • 42
  • 532
  • 579
Cloy
  • 2,141
  • 23
  • 32
  • 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,476
  • 1
  • 17
  • 28