G'day,
I have to loop through an array of objects and perform an operation on each item where the result is returned asynchronously. I'm very new to async/await style of coding in Swift and could not figure out how to find an easier solution. Appreciate any help. Please find the sample code below. I tried surrounding it inside Task but it does not work due to compiler error.
func performOperation(ids: [UUID]) -> [TypeA] {
var output: [TypeA] = []
for id in ids {
Task {
let results = await someAsyncFunction(id)
output.append(contendsOf: results) // Does not compile.
}
}
return output
}
func someAsyncFunction(id: UUID) async -> [TypeA] {
// third party framework function.
}