1

I am getting the below error while trying to get data from PHP sever.
URLSession being initialised seems to have an error at shared.
Kindly help me to get swift3 equivalent.

This is error message and sample code below :

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

let task = URLSession.shared.dataTask(with: PhpReqVar)
{
    data, response, error in
    // Code Todo
}

Thanks in advance.

1
  • 2
    Make sure that PhpReqVar is of type URLRequest, not NS(Mutable)URLRequest Commented Oct 25, 2016 at 12:39

2 Answers 2

1

Your completion handler does not take any parameters and you are not closing the (.

Try this (assuming that PhpReqVar is of type URL or URLRequest):

let task = URLSession.shared.dataTask(with: PhpReqVar)
{
    data, response, error in
    //CodeTodo
}
Sign up to request clarification or add additional context in comments.

Comments

1

The code should be the following:

let task = URLSession.shared.dataTask(with: PhpReqVar as URLRequest) { (data, response, error) in
 //code here    
}

You have missed to add the completionHandler's parameters. Also specifying PhpReqVar as URLRequest, not as MutableURLRequest.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.