I want to encode the +
character in my url string, I tried to do that this way:
let urlString = "www.google.com?type=c++"
let result = string.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
but this won't work for +
.
any idea? Thanks.
Update:
What's more this type=
parameter in the url is dynamic, I wouldn't do some implicite replacement on the +
character. This type=
parameter represents a UITextField value, so there can be typed-in anything.
I'm also curious why addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
won't work in this particular case?