0

I use Alamofire 4.0, Swift 4.2 and Xcode 10.2 to request Http Api I have url constant:

let weatherUrl = "http://api.openweathermap.org/data/2.5/weather"

And function:

func getWeatherData(url: String, parameters: [String : String])
    {
        Alamofire.Request(url, parameters: parameters).responseJSON
        {
                response in
        }

getWeatherData(url: weatherUrl, parameters: params)

And Xcode notify me:"Cannot convert value of type 'String' to expected argument type 'URLSession'".

Alamofire

What is the problem?

6
  • shouldnt one of your parameters be [URL : String] or [String: URL] ? you also defined url:String , should it be url: URL Commented Jan 28, 2019 at 18:18
  • Which line? Which variable? Provide details in your question. Commented Jan 28, 2019 at 18:21
  • @rmaddy in line: Alamofire.Request(url, method: .get, parameters: parameters).responseJSON. I have updated the image of the problem! Commented Jan 28, 2019 at 18:25
  • The error is pretty clear. The first argument in the call to Alamofire.Request needs to a URL, not a String. Commented Jan 28, 2019 at 18:27
  • @rmaddy Thank you! I fixed it. :) Commented Jan 28, 2019 at 18:32

2 Answers 2

0

You can try with as following code. Because URL is of type URLConvertible.

let url = URL(string: myURLString)

Sign up to request clarification or add additional context in comments.

Comments

0

You're using Request, which is a type, and not request, which is the method you're looking for.

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.