Search code examples
iosswiftavfoundationxcode13swift-concurrency

How to call original synchronous method that has async overload in Xcode 13


Recently switched to Xcode 13.

I have an AVAsset writer, and trying to call the method

writer.finishWriting()

which now has an async version, as well as the synchronous version.

I want to call the original synchronous version, but am getting the error:

"'async' call in a function that does not support concurrency. 
Add 'async' to function to make it asynchronous"

How can I call the original synchronous/pre-Xcode 13 version?


Solution

  • It looks like you forgot to add the trailing closure that the original function is expecting.

    You want to use finishWriting(completionHandler:). The definition takes a trailing closure, completionHandler:

    func finishWriting(completionHandler handler: @escaping () -> Void)
    

    If you add the trailing closure:

    writer.finishWriting {
        /* do stuff */
    }
    

    the code will compile as expected.