Daily iOS
Concurrency

Ordered concurrent downloads

You're given an array of image ids [3, 1, 2]. Download each image concurrently, but display them on screen in id order (1, 2, 3). How would you do that with Swift Concurrency?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Add a child task per id in withThrowingTaskGroup to download at the same time, collect results as (id, image) into a dictionary, then pull them out in ids.sorted() order. The point is separating completion order from display order.

Share a question