I have the following code in Swift 5.5 and iOS 15
func getReviewIds() {
var reviewIds: [Int] = []
Task {
let ids = await getReviewIdsFromGoogle()
reviewIds.append(contentsOf: ids)
}
print("outside")
}
func getReviewIdsFromGoogle() async -> [Int] {
await withUnsafeContinuation { continuation in
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
continuation.resume(returning: [1,2,3])
}
}
}
I get an error in getReviewIdsFromGoogle
function on the following line:
reviewIds.append(contentsOf: ids)
Mutation of captured var 'reviewIds' in concurrently-executing code
I know that I can make the getReviewIdsFromGoogle
an async
function instead of using the async
closure, but how can I solve this using the closure.
reviewIds
? – Ballyhoo