gpt4 book ai didi

ios - "' isSuccess ' is inaccessible due to ' 内部 ' protection level",AlamoFire 不像以前那样工作

转载 作者:行者123 更新时间:2023-12-01 19:30:10 25 4
gpt4 key购买 nike

我在 swift 上使用 alamoFire,但我遇到了这个问题:“isSuccess' 由于'内部'保护级别而无法访问”。我试过this我也试过this ,这是我的代码:

AF.request(jsonURL, method: .get, parameters: parameters).responseJSON { (response) in
if response.result.isSuccess { //problem is here
print("Got the info")
print(response)

let flowerJSON : JSON = JSON(response.result.value!)

let list = flowerJSON["..."]["..."]["..."].stringValue

print(list)

}
}

最佳答案

result 现在是内置的 Result enum 类型,这意味着您可以对其进行模式匹配。你的代码可以改写为:

AF.request("", method: .get, parameters: [:]).responseJSON { (response) in
if case .success(let value) = response.result {
print("Got the info")
print(response)

let flowerJSON : JSON = JSON(value)
...
}
}

如果您还想要错误情况,请使用 switch 语句:

switch response.result {
case .success(let value):
// ...
case .failure(let error):
// ...
}

关于ios - "' isSuccess ' is inaccessible due to ' 内部 ' protection level",AlamoFire 不像以前那样工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63325754/

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