ddwdwwf drewret
ddwdwwf drewret

Reputation: 69

How to convert String URL in Swift 5?

Im having a big trouble with URl I want to use url for almofire , but unforutnately it always return nil or ortherwise , this solutuin return valid URL but with weird $$*%&$( in front of https:// an resulting to always got nil response

    let req = "​https://api-staging.xx.oo/v1/s-locations/"
    
    guard let percentReq = req.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed ) else { return nil }
    
    let urlReq = URL(string: percentReq)!

// work , url got , but fetch nothing

     let urlReq = URL(string: req)! 

// error FATAL

Upvotes: 0

Views: 3811

Answers (1)

Adis
Adis

Reputation: 4552

Honestly, looks like you managed to get some trash into the string by copy-pasting, I'm assuming it's encoding or something. This code from below works just fine:

let test = "https://api-staging.xx.oo/v1/s-locations/"
let url = URL(string: test)

Upvotes: 2

Related Questions