Cloy
Cloy

Reputation: 2181

NSURL - encode '&' with spaces

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 '&'

Upvotes: 0

Views: 430

Answers (1)

MjZac
MjZac

Reputation: 3526

You can use .urlHostAllowed characterset.

let escapedString = someString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)

Upvotes: 2

Related Questions