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
  • 314,917
  • 42
  • 532
  • 579
Anik
  • 61
  • 8

0 Answers0