Matthew Xavier Jacome Matthew Xavier Jacome - 7 months ago 39
Swift Question

Why do I get ambiguous reference to member error?

Using the following code

if let url = NSURL(string: "") {

let task = session.dataTask(with: url, completionHandler: { (data, response, error) in
// check against error
if let error = error {
print("Data task failed with error: \(error)")



I get the following

Ambiguous reference to member 'dataTask(with:completionHandler:)'

Why and how can I fix this?

Answer Source

Error is in the NSURL. Change the

if let url = NSURL(string: "")  


if let url = URL(string: "") {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download