'value' is inaccessible due to 'internal' protection level

后端 未结 3 2015
傲寒
傲寒 2021-01-28 14:07

Setting up API for openweathermap. However, when it comes to setting up this:

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [C         


        
相关标签:
3条回答
  • 2021-01-28 14:37
    switch response.result {
            
            case .success(let value):
                print("Alamo value: \(value)")
                break
            case .failure(let error):
                print("Alamo error: \(error)")
                break
            }
    
    0 讨论(0)
  • 2021-01-28 14:55

    Thanks for trying Alamofire 5! This error is a bit misleading, as the Swift compiler is trying to be helpful and letting you know there's an internal property value on response.result that you can't access. However, this is an internal Alamofire extension, as we moved to the Result type provided by the Swift standard library in Alamofire 5 beta 4. The system Result does not offer the the value and error properties that Alamofire's previously provided Result type did. So while we have extensions internally to provide functionality to us, they do not exist publicly for use by your app.

    The ultimate solution here is up to you. You can extend Result yourself to offer the properties (feel free to use the Alamofire implementation) or you can do without the properties and switch over the response.result value to extract the response value. I would suggest using switch for now, as it forces you to consider the .failure case.

    0 讨论(0)
  • 2021-01-28 14:58

    In the latest beta 4 version Alamofire switched to using the new standard Result type, so the convenience properties we used to have have been made internal. Now you can switch over the result like this:

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

    Or you can make similar extensions in your own project. They won't be offering the extensions publicly anymore.

    0 讨论(0)
提交回复
热议问题