iOS Concurrency with GCD & Operations

Sep 12 2023 · Swift 5.8, macOS 13, iOS 16, Xcode 14.3

Part 1: Grand Central Dispatch

06. The Right Way to Download Images

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: 05. Challenge: A Better Way to Download Images Next episode: 07. Use a Group of Tasks

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.

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

The Right Way to Download Images

There’s an even easier way to download images off the main queue.

func downloadImageWithUrlSession(index: Int) {
  URLSession.shared.dataTask(with: images[index].url) {
    [weak self] data, _, _ in

  }.resume()
}
guard let self else { return }
if let data, let decodedImage = UIImage(data: data) {

}
DispatchQueue.main.async {
  self.images[index].image = decodedImage
}
//store.downloadImageOffMainQueue(index: image.id)
store.downloadImageWithUrlSession(index: image.id)