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
Nsdateformatter Datefromstring Always Returns Nil
Get User Swiping Direction in Uipageviewcontroller
Uipickerview as Inputview of Uitextfield
Cncopycurrentnetworkinfo with iOS 13
Switching from Xcode3 to Xcode4 - Can't Load Programs Onto Older Ipod Touch
Xcode 7 Crash: [Nslocalizablestring Length] 30000
Pdfkitten Is Highlighting on Wrong Position
Draggesture on a VStack with Lot of Buttons, How to Detect When the Drag Is Inside a Button
How to Get All Available Wifi Network Name Listings in iOS
How to Get the iPhone Type from Simulator (Ios)
Not Getting the Email Using Google Authentication in Firebase
How to Control My Headset for My Music Player
Xcode Doesn't Write Anything to Output Console
Where Does a Swift iOS Application Begin Its Life
Wkwebview and Uimenucontroller
How to Do Authorization and Login with Wechat Using the iOS Sdk
Access Iphone's Built-In Ringtones
Nsstrikethroughstyleattributename , How to Strike Out the String in iOS 10.3