I increased the target version, and xcode started giving me an error

Expression is 'async' but is not marked with 'await'" on each usage of NSManagedObjectContext.perform().

let context: NSManagedObjectContext = ... context.perform{...}

It thinks I use newer method

NSManagedObjectContext.perform<T>(schedule::() throws -> T) async rethrows -> T,

but I don't.

How to make xcode to compile with old perform(() -> Void)?

Adding explicit closure header

let context: NSManagedObjectContext = ... context.perform{() -> Void in ...}

is not helpful.

koen's user avatar

koen

5,8847 gold badges60 silver badges104 bronze badges

Alexey's user avatar

Your call must have been in an async context. Apparently in an async context, Swift prioritises resolving to async methods.

You can have it resolve to the non-async method by introducing a synchronous context. For example, you can write a local function like this

func someAsyncFunction() async { func helper() { someContext.perform { ... } } helper() }

More generally, you can write

func run<R>(block: () -> R) -> R { block() } ... func someAsyncFunction() async { run { someContext.perform { ... } } }

Sweeper's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.