Created
December 8, 2019 16:45
-
-
Save damienissa/ec0e22139f9f9045b64e360f4de01a30 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import Combine | |
| extension URLSession { | |
| @discardableResult | |
| func dataTaskPublisher<Response: Decodable>(for request: URLRequest, type: Response.Type) -> AnyPublisher<Response, Error> { | |
| dataTaskPublisher(for: request) | |
| .map { $0.data } | |
| .decode(type: Response.self, decoder: JSONDecoder()) | |
| .receive(on: DispatchQueue.main) | |
| .eraseToAnyPublisher() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment