0

Is there a way to "callback" to the main thread once CoreData persistentContainer is complete? Similar to a completion handler? I'd like to update the UI once CoreData is done writing data to my SQLite database.

This is what I have. Once backgroundContext.perform is done, I'd like to callback to the main thread.

let backgroundContext = persistentContainer.newBackgroundContext()
persistentContainer.viewContext.automaticallyMergesChangesFromParent = true

backgroundContext.perform {
    //Computationally heavy write to SQLite database. Once complete, callback to main thread 
}

I've tried looking at a few different approaches but nothing seems to work or gives weird behavior. Any help would be appreciated.

HappyAppy
  • 23
  • 2
  • Does this answer your question? [Calling a method on the main thread?](https://stackoverflow.com/questions/5606145/calling-a-method-on-the-main-thread) – HangarRash Dec 08 '22 at 16:23
  • Check out Bring Core Data concurrency to Swift and SwiftUI from #wwdc21 https://developer.apple.com/wwdc21/10017 – lorem ipsum Dec 08 '22 at 16:49

0 Answers0