Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public class DataFetcher : ObservableObject{
var cancellable : Set<AnyCancellable> = Set()
static let shared = DataFetcher()
func getJokes(completion: @escaping ([ChuckValue]?) -> Void){
let urlComponents = URLComponents(string: "")!
URLSession.shared.dataTaskPublisher(for: urlComponents.url!)
.decode(type: ChuckJokes.self, decoder: JSONDecoder())
.receive(on: DispatchQueue.main)
.sink(receiveCompletion: { completion in
}) { response in
.store(in: &cancellable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment