【问题标题】:Alamofire.request() errors out in Xcode 12Xcode 12 中的 Alamofire.request() 错误
【发布时间】: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


【解决方案1】:

试试这个可能对你有用:)

AF.request(url,method: .get).responseString{
                        responce in
                     }

【讨论】:

  • 嘿!感谢您的帮助,我试过了,我在方法内部的行中有三个不同的错误,我真的不明白为什么,可能是因为它没有将 AF 读取为 Alamofire?错误是:由于“内部”保护级别,“isSuccess”无法访问“Result”类型的值没有成员“值”在范围内找不到“bitcoinJSON”
  • 因为在这个版本的 alamofire 中没有名为 issucess 的方法,所以你可以用 if (try? responce.result.get()) != nil{ 替换它。 ,希望对你有帮助,别忘了点赞
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-03
  • 2021-01-18
  • 1970-01-01
  • 1970-01-01
  • 2021-01-10
相关资源
最近更新 更多