Hey,
I want to switch from Combine to the new Concurrency feature.
In the documentation on Swift, this sample is used:
async let firstPhoto = downloadPhoto(named: photoNames[0])
async let secondPhoto = downloadPhoto(named: photoNames[1])
async let thirdPhoto = downloadPhoto(named: photoNames[2])
let photos = await [firstPhoto, secondPhoto, thirdPhoto]
show(photos)
How would you transform this code using an Array
and map
?
let names = ["foo", "bar", "bar"]
let tasks = names.map { photoName in
downloadPhoto(named: photoName)
}
let photos = await tasks
show(photos)