0

I have problem with following code: String URL works fine in browser, but cant create URL from it.

    let stringURL = "http://dev.rationaletech.com:8063/Images/Offers/1/20%25-off-at-gloria-jean’s-coffee-6b62e43e-ba2b-4c9c-9f70-8b24e2a514a0.jpg"
    let url = URL(string:stringURL)

url property is nil after.

I have realized that problem is caused by ’ character inside link.

Any suggestions?

Update:

I have done next:

    let charactesSet = CharacterSet(charactersIn: "#<>^`{|}").inverted
    if let stringUrl = stringURL.addingPercentEncoding(withAllowedCharacters: charactesSet){
        let url = URL(string:stringURL)
    }

where charactesSet is URLHostAllowedCharacterSet "#%/<>?@\^`{|}" without %. And now i have: http://dev.rationaletech.com:8063/Images/Offers/1/20%25-off-at-gloria-jean%E2%80%99s-coffee-6b62e43e-ba2b-4c9c-9f70-8b24e2a514a0.jpg which works. I dont like this solution, will talk to server side. tnx

sladjann
  • 91
  • 1
  • 6

0 Answers0