"'isSuccess' is inaccessible due to 'internal' protection level",阿拉莫火不像以前那样工作了



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

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枚举类型,这意味着你可以对它进行模式匹配。你的代码可以重写为:

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):
// ...
}

最新更新