Ambiguous reference to member ‘dataTask(with:completionHandler:)’

Ambiguous reference to member ‘dataTask(with:completionHandler:)’
let request = NSMutableURLRequest(url: URL(string: “Your API URL here” ,param: param))!,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval:”Your request timeout time in Seconds”)
request.httpMethod = “POST”
request.allHTTPHeaderFields = headers as? [String : String]
let dataTask = URLSession.shared.dataTask(with: request ) {data,response,error in
let httpResponse = response as? HTTPURLResponse

    if (error != nil) {
     print(error)
     } else {
     print(httpResponse)
     }

    DispatchQueue.main.async {
       //Update UI here
    }

}
dataTask.resume()

Solution: just make request as URLRequest
let dataTask = URLSession.shared.dataTask(with: request as URLRequest)

Read More: