gpt4 book ai didi

ios - Alamofire 5 : Value of type 'Result' has no member 'value'

转载 作者:行者123 更新时间:2023-12-01 15:24:16 45 4
gpt4 key购买 nike

Alamofire 5 中的新错误是什么?因为上次没有遇到错误。下面是完成的代码。任何使用 Alamofire 的人都面临这个问题?

import Foundation
import Alamofire

class MyAppService {
static let shared = MyAppService()
let url = "http://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)
}
}
}

最佳答案

您必须提取 result值如下,

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

关于ios - Alamofire 5 : Value of type 'Result<Data, AFError>' has no member 'value' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58177841/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com