A Swift package that provides an extension on URLSession
to allow requesting data synchronously.
let (data, response, error) = URLSession.shared.synchronousDataTask(with: request)
// ... unwrap `data`, `response`, and `error` as per usual
do {
let (data, response) = try URLSession.shared.throwingSynchronousDataTask(with: request)
// ... `data` and `response` are not `Optional`
} catch {
print(error)
}
do {
let decoder = JSONDecoder() // or any `TopLevelDecoder`
let model: SomeCodableModel = try URLSession.shared.synchronousDataTask(with: request, decoder: decoder)
// .. proceed with `model`, a `SomeCodableModel` instance
catch {
print(error)
}