Alamofire. Помогите разобраться


#1

Пытаюсь разобраться с alamofire. Хочу получать данные о погоде c openweathermap. Запрос должен состоять вот таким образом api.openweathermap.org/data/2.5/weather?q=Moscow&appid=e61077771960c6d8d4d67d0c3bc7c638

Если я напишу вот так, то Request получается правильный, но Response все равно nil.

let weatherUrl = "api.openweathermap.org/data/2.5/weather?q="

func getWeatherFor(city: String) {
    request(weatherUrl + city + "&appid=e61077771960c6d8d4d67d0c3bc7c638").responseJSON { (response) in
        print("Request: \(String(describing: response.request))")   // original url request
        print("Response: \(String(describing: response.response))") // http url response
        print("Result: \(response.result)")
        
        if let json = response.result.value {
            print("JSON: \(json)") // serialized json response
        }
    }
}

Пытался передавать сити как параметр
тогда из weatherUrl убираю “?q=”

let weatherUrl = "api.openweathermap.org/data/2.5/weather" 
func getWeatherFor(city: String) {

    let params = ["q": city]
    Alamofire.request(weatherUrl, method: .get, parameters: params).responseJSON { (response) in
        
        print("Request: \(String(describing: response.request))")   // original url request
        print("Response: \(String(describing: response.response))") // http url response
        print("Result: \(response.result)")                         // response serialization result
    }
}

Но в таком случае я не знаю как добавить в конце вот эту часть “&appid=e61077771960c6d8d4d67d0c3bc7c638”

Пробовал так
let cityWithID = city + "&appid=e61077771960c6d8d4d67d0c3bc7c638"
и в params передавать cityWithID, но получается не тот запрос который нужен
api.openweathermap.org/data/2.5/weather?q=Moscow%26appid%3De61077771960c6d8d4d67d0c3bc7c638

Подскажите пожалуйста что я делаю не так, и как правильно.


#2

Это очень странно, но вот так это работает


а вот так приходит нил


#3

Вы http:// забыли добавить во втором случае