I am having a issue where I have to remove the backlash(/) from the end of the url. actually I had removed last path component by using deleting url.deletingLastPathComponent() and now generated url contains / at the end. So how can I remove it to make the url workable.
CodePudding user response:
This should work fine. Coming to required answer, we can't do string manipulation for URLs. Solution would be
- Remove last path component
- Remove /
- Create url again
url.deleteLastPathComponent()
var address = url.absoluteString
address.removeLast()
url = URL(string: address)
Spaces are being replaced by because of URL encoding. e.g.
var name = "Rajesh Budhiraja"
name.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
now name will be 'Rajesh Budhiraja'
you can undo this via
name.removingPercentEncoding