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

标签 ios json swift alamofire

我在 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/

相关文章:

HTML::模板 Perl

swift - 无法使用 segues 在 View Controller 之间传递数据(Xcode 7)(Swift)

ios - swift 静态库

ios - 未在 Storyboard 中的自定义对象上调用 ViewDidLoad

ios - Everyplay 拿着我的麦克风 UNITY3D iOS

IOS是否可以在不强制转换的情况下获取NSFetchedResultsController字段的数据

javascript - 是否可以通过添加手动数据来更改从 JSON 数据生成的表?

javascript - 从 angularjs 中的多个 json 数组动态检索数据

swift - Firebase 身份验证 : user profile changes are not synced to other devices?

swift - 在 Swift 中,当协议(protocol)被限制为从类继承时会发生什么?