1

How to Encode the & to %26 in Swift 4.1?

This is what I tried:

func encodeString(string: String) -> String {
    let unreserved = "!@#$%^&*()_+<>?:,.;'*"
    let allowed = NSMutableCharacterSet.symbol()
    allowed.addCharacters(in: unreserved)
    return string.addingPercentEncoding(withAllowedCharacters: allowed as CharacterSet)!
}
rmaddy
  • 307,833
  • 40
  • 508
  • 550
Anik
  • 61
  • 8

0 Answers0