Alamofire 5: Value of Type 'Result<Data, Aferror>' Has No Member 'Value'

Alamofire 5: Value of type 'ResultData, AFError' has no member 'value'

You have to extract the result value as below,

func getCurrentUser(_ completion: @escaping (SomeRequest?) -> ()) {
let path = "/somePath"
AF.request("\(url)\(path)").responseData { response in
switch response.result {
case .success(let value):
print(String(data: value, encoding: .utf8)!)
completion(try? SomeRequest(protobuf: value))
case .failure(let error):
print(error)
completion(nil)
}
}
}

Value of type 'ResultAny, AFError' has no member 'value' JSON

First of all check your spelling, erro is pointless.

According to the error the value for result is Result<Any, AFError>, Result is an enum with associated types and two cases: success and failure

The syntax must be something like

AF.request(URL_LOGIN, method: .post, parameters: body, encoding: JSONEncoding.default, headers: header).responseJSON { (response) in

switch response.result {
case .success(let result):
if let json = result as? Dictionary<String, Any> {
if let email = json["user"] as? String {
self.userEmail = email
}
if let token = json["token"] as? String {
self.authToken = token
}
}
self.isLoggedIn = true
completion(true)
case .failure(let error):
completion(false)
debugPrint(error)
}
}

The logic is not very logic. I'm sure that self.isLoggedIn is not supposed to be true if email and token are invalid and should be set to false when an error occurs.

Value of type 'ResultString' has no member 'error' [Alamofire, Swift 5]

Change

Result

to

Alamofire.Result

Or create a typealias as,

typealias AFResult = Alamofire.Result

and change Result to AFResult.



Related Topics



Leave a reply



Submit