Created
February 20, 2020 19:48
-
-
Save 0xLeif/ba124600eb294b6b15bcbc968c0263af to your computer and use it in GitHub Desktop.
Init Call for GitHubSocial
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 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://developer.github.com/v3/repos/#list-all-public-repositories