1

I have found the same question but not worked for me. thats why I'm posting this again. The following code gives me an error.

Could not cast value of type 'Foundation.URLRequest' to 'Alamofire.URLConvertible'

the code sample:

    let url = (wURL).replacingOccurrences(of: "(f_id)", with: String(conID))
    let _url = URL(string: url)
    var urlRequest = URLRequest(url: _url!)
    urlRequest.timeoutInterval = TimeInterval(exactly: 30)!
    
    let finalUrl = urlRequest as! URLConvertible

What am I missing?

mmk
  • 182
  • 3
  • 18

1 Answers1

1

You can't do it, because for URLRequest there is special protocol URLRequestConvertible.

let realURL: URL = URL(string: "https://google.com")!

let url: Alamofire.URLConvertible = realURL

let urlRequest: Alamofire.URLRequestConvertible = URLRequest(url: realURL)

AF.request(urlRequest).responseJSON {
    print($0)
}
えるまる
  • 2,409
  • 3
  • 24
  • 44