我在 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枚举类型,这意味着您可以对其进行模式匹配。您的代码可以重写为:
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):
// ...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)