gpt4 book ai didi

swift - 无法将类型 'String' 的值转换为预期参数类型 'URLSession'

转载 作者:行者123 更新时间:2023-11-30 10:51:36 28 4
gpt4 key购买 nike

我使用 Alamofire 4.0、Swift 4.2 和 Xcode 10.2 来请求 Http Api我有 url 常量:

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

及功能:

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

getWeatherData(url: weatherUrl, parameters: params)

Xcode 通知我:“无法将类型‘String’的值转换为预期的参数类型‘URLSession’”。

Alamofire

问题是什么?

最佳答案

您可以尝试使用以下代码。因为 URL 的类型为 URLConvertible。

让 url = URL(字符串: myURLString)

关于swift - 无法将类型 'String' 的值转换为预期参数类型 'URLSession',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54407876/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com