使用Alamofire的服务器请求并在Xcode 11 Beta 3中合并

时间:2019-07-10 09:57:11

标签: ios alamofire swiftui

我正在尝试使用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

但我不知道如何使用它。...

0 个答案:

没有答案