0

I am currently working on a project where I am saving to my main context from a background Thread. Like so:

DispatchQueue.global().async {
    ... 

    context.save()
}

I have now read that this is not okey, since every thread has it's own context?

My question is that I had this code for a long time now and it worked nearly perfectly (no errors!). Just now I am noticing some weird behaviors which is why I came to researching it.

Does anyone know why? Maybe also what I should do instead? I have a huge calculation that I don't want to do on the main-thread. (which is needed for the object I want to save to core-data)

Thank you:-)

Donkey
  • 43
  • 4
  • `context.perform { context.save() }` to ensure that you'll save in the correct thread (but then, the save will be done in main thread). If you app is not complexe and not that much concurrency issue, but using https://stackoverflow.com/a/41249918/1801544 you might see issues. – Larme Dec 01 '20 at 10:51
  • Thanks:))))))))) – Donkey Dec 01 '20 at 17:07

0 Answers0