Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import Foundation
extension URL {
func getFromPublisher<T: Codable>(property: inout Published<T>.Publisher) {
URLSession.shared.dataTaskPublisher(for: self)
.receive(on: DispatchQueue.main)
.map(\.data)
.decode(type: T.self, decoder: JSONDecoder())
.print()
.assertNoFailure()
.assign(to: &property)
}
}
extension Date {
static var currentTime: String {
let formatter = DateFormatter()
formatter.dateFormat = "HH:mm"
return formatter.string(from: Date())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment