Alamofire 5:类型为'Result< Data,AFError>'的值没有成员“值”

编程入门 行业动态 更新时间:2024-10-27 10:18:50
本文介绍了Alamofire 5:类型为'Result< Data,AFError>'的值没有成员“值”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Alamofire 5是否有新错误?因为上次没有遇到错误。下面是完成的代码。是否有人使用Alamofire来面对这个问题?

Is the a new error in Alamofire 5? as this wasn't running into bugs last time. Below are the code which are done. Anyone who used Alamofire facing this?

import Foundation import Alamofire class MyAppService { static let shared = MyAppService() let url = "127.0.0.1:5000" private init() { } func getCurrentUser(_ completion: @escaping (SomeRequest?) -> ()) { let path = "/somePath" AF.request("\(url)\(path)").responseData { response in if let data = response.result.value { //error shown here (Value of type 'Result<Data, AFError>' has no member 'value') let contact = try? SomeRequest(protobuf: data) completion(contact) } completion(nil) } } }

推荐答案

您必须提取结果值,如下所示,

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) } } }

更多推荐

Alamofire 5:类型为'Result&lt; Data,AFError&gt;'的值没有成员“值”

本文发布于:2023-11-26 03:38:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632486.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:成员   类型   Result   Alamofire   amp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!