【发布时间】:2021-03-14 10:28:37
【问题描述】:
我有一个使用名为 getPriceData() 的 alamofire 网络方法,其中有一个 Alamofire.request(url, method: .get) 会出错两次,尽管在另一个应用程序项目中使用相同的方法完全相同并且工作正常。错误:
模块“Alamofire”没有名为“request”的成员
无法根据成员“get”推断上下文基础
方法:
func getPriceData(url: String) {
Alamofire.request(url, method: .get).responseJSON {
response in
if response.result.isSuccess {
let priceJSON: JSON = JSON(response.result.value!)
self.updatePriceData(json: bitcoinJSON)
} else {
self.bitcoinPriceLabel.text = "N/A"
}
}
}
这是一段代码和两个错误的屏幕截图: The method and the errors
【问题讨论】:
-
请确保您对两个项目使用相同的 Alamofire Pod 版本。可能该方法在最新的 pod 版本中发生了变化。
-
阅读 Alamofire 的用法来帮助自己。 github.com/Alamofire/Alamofire/blob/master/Documentation/…
-
我检查了 alamofire 版本,旧项目是 4.9.1,新项目是 5.4.0
标签: swift xcode alamofire swift5