Created
November 14, 2020 23:40
-
-
Save sturdysturge/684d212551d774bdc357e6c265f456ed 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 SwiftUI | |
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()) | |
.assertNoFailure() | |
.assign(to: &property) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment