Fixing the “Async call in a function that doesn’t support concurrency” error in Swift
The error message may also say “Cannot pass function of type ‘() async -> Void’ to parameter expecting synchronous function type”.
Why am I getting this error?
You are using Swift’s async await syntax and calling an async function in a function that does not support async await. If you have the following function that calls an async function:
func myFunction() {
await asyncFunction()
}
You are going to get the “Async call in a function that doesn’t support concurrency” build error because myFunction
is not an async function.
Apple added async await support to Swift in 2021 so the support is relatively new. Many of Apple’s frameworks do not support the new async await syntax.
Apple’s ASWebAuthenticationSession
class, which apps use to log into websites, does not support async await. When you create an instance of ASWebAuthenticationSession
, you supply a completion handler that runs after a successful login. If you make an async function call in the completion handler, you’ll get the “Async call in a function that doesn’t support concurrency” build error.
Ways to fix the error
The most common way to fix the error is to place the call to the async function in a Task
block.
Task {
await asyncFunction()
}
If the error occurs in a function you wrote, you can fix the error by marking that function as async.
func myFunction() async {
await asyncFunction()
}
Don’t forget to add await
when calling the function you marked as async.