Hardware, Software, Coding, Game, or Windows⏱️ 3 min read📅 2026-06-03

How to Fix: Swift 3 URLSession.shared() Ambiguous reference to member 'dataTask(with:completionHandler:) error (bug)

SEO meta description 140-155 characters.

Quick Answer: 1-2 sentences of direct conversational advice.

In Swift 3, the `dataTask(with:completionHandler:)` method has been renamed to `dataTask(with:queue:)`. This change affects how you create and execute tasks in `URLSession`. The error occurs because the compiler is unable to resolve the ambiguous reference to the `dataTask(with:completionHandler:)` method. To fix this issue, update your code to use the correct method name.

To resolve this issue, replace all instances of `dataTask(with:completionHandler:)` with `dataTask(with:queue:)`. The corrected line should look like this: let task = URLSession.shared().dataTask(with: r

The updated code will be: let listUrlString = "http://bla.com?batchSize=" + String(batchSize) + "&fromIndex=" + String(fromIndex) let myUrl = URL(string: listUrlString); let request = NSMutableURLRequest(url:myUrl!); request.httpMethod = "GET"; let task = URLSession.shared().dataTask(with: r

Additionally, ensure that you are using the correct completion handler. In Swift 3, the completion handler is optional and should be passed as a parameter to the `completionHandler` closure.

To fix this issue, update your code to use an optional completion handler like this: let task = URLSession.shared().dataTask(with: r

The updated code will look like this: let listUrlString = "http://bla.com?batchSize=" + String(batchSize) + "&fromIndex=" + String(fromIndex) let myUrl = URL(string: listUrlString); let request = NSMutableURLRequest(url:myUrl!); request.httpMethod = "GET"; let task = URLSession.shared().dataTask(with: r

By making these changes, you should be able to resolve the ambiguous reference to member `dataTask(with:completionHandler:)` error and successfully use your JSON parsing code in Swift 3.

🔍 Why This Happens

    ✅ Best Solutions to Fix It

    Update System Settings

      Alternative Advanced Fix

        💡 Conclusion

        Did this fix your problem?

        If not, try searching for specific error codes.

        🔍 Search Error Database