我正在尝试使用Alamofire向服务器发送请求,以下代码在Xcode 11 beta 2中运行良好,但是由于beta 3版本,我收到了错误
Member 'init' in 'AnyPublisher<Root, APIServiceError>' produces result of type 'AnyPublisher<Output, Failure>', but context expects 'AnyPublisher<Root, APIServiceError>'
func getResponse(from url: URL) -> AnyPublisher<Root, APIServiceError> {
return .init { subscriber in
Alamofire.request(url.absoluteString)
.responseData { response in
switch response.result {
case .success:
do {
let serverResponse = try JSONDecoder().decode(Root.self, from: response.data!)
_ = subscriber.receive(serverResponse)
} catch (let error) {
subscriber.receive(completion: .failure(.parseError(error)))
}
case .failure(let error):
subscriber.receive(completion: .failure(.responseError))
}
}
}
}
他们将init
的{{1}}更改为
AnyPublisher
但我不知道如何使用它。...