Get immediate access to this and over 1,500+ other videos and books.

Boost your skills with a raywenderlich.com Beginner subscription. With over 60+ video courses and our core foundational programming books bundled in one subscription, it’s simply the best investment you can make in your development career.

Challenge: Fetch Data Over the Network

In this challenge episode you will put your existing knowledge about URLSession to the test in order to download and display data downloaded from the network.

Contributors

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

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.

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
}

Reviews

Comments