“isSuccess”由于“internal”保护级别而无法访问,Alamofire不再像以前那样工作

4

我正在使用Swift上的Alamofire,但我遇到了这个问题:"isSuccess"由于"internal"保护级别而无法访问。

我尝试过这个这个,以下是我的代码:

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)
            
        }
    }
1个回答

12

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接