Skip to content

Instantly share code, notes, and snippets.

@0xLeif
Created February 20, 2020 19:48
Show Gist options
  • Save 0xLeif/ba124600eb294b6b15bcbc968c0263af to your computer and use it in GitHub Desktop.
Save 0xLeif/ba124600eb294b6b15bcbc968c0263af to your computer and use it in GitHub Desktop.
Init Call for GitHubSocial
import Foundation
import UIKit
import Combine
extension AnyPublisher {
func value(_ closure: @escaping ((Output) -> Void)) -> AnyCancellable {
sink(receiveCompletion: { _ in }, receiveValue: closure)
}
}
// MARK: Requests
var bag = [AnyCancellable]()
let request = URLRequest(url: URL(string: "https://api.github.com/repositories")!)
URLSession.shared.dataTaskPublisher(for: request)
.eraseToAnyPublisher()
.value { (output) in
print(output.response)
do {
let jsonObjects = try JSONSerialization.jsonObject(with: output.data, options: []) as? [Any]
print(jsonObjects?.first)
} catch {
print(error.localizedDescription)
}
}
.store(in: &bag)
@0xLeif
Copy link
Author

0xLeif commented Feb 20, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment