I am working on a Swift 3.0 app, in which I am making a rest api call. The problem is that there may be a space in query string parameter, which is causing the URL to become nil. It works fine when there is no space in that parameter. But with a space it does not work.
Any help is appreciated.
Thanks
You could do something like this to escape the spaces and other characters which may interfere with the request processing:
var escapedAddress = address.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())
For Swift 3, use the following:
let escapedAddress = address.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With