Beginning Networking with URLSession

Sep 13 2022 · Swift 5.6, iOS 15, Xcode 13.4.1

Part 1: Introduction to URLSession & Concurrency

07. Challenge: Fetch Data Over the Network

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 06. Get Data from a Session Next episode: 08. Conclusion

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 07. Challenge: Fetch Data Over the Network

URLSessionConfiguration - Apple Developer URLSession - Apple Developer

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

Welcome to the seventh episode! Time for a little challenge for you.

let configuration = URLSessionConfiguration.default
let session = URLSession(configuration: configuration)
Task {

}
Task {
  let (data, response) = try await session.data(from: url)
}
guard let httpResponse = response as? HTTPURLResponse,
      (200..<300).contains(httpResponse.statusCode)
else {
  throw MediaError.requestFailed
}
guard let mediaResponse = try? JSONDecoder().decode(MediaResponse.self, from: data) else {
  throw MediaError.responseDecodingFailed
}
await MainActor.run {
  musicItems = mediaResponse.results
}