I'm working on an app that uses core data and I'm aware that this is not thread safe but struggling to understand how to manage this correctly. Let me explain what I have so far...
I've created a singleton the initiates the managed object and is then available to all other classes, this appears to be working correctly as the same managed object address is received by all classes.
I then have two clases that are executed in this order...
- Data load. This gets the record count and if zero loads the core data base.
- Tableview that then displays the data stored in step 1.
My problem is that step 1. Is always returning zero records, and step 2. Is working and returns the correct record count.
Having done some testing the problem with 1. Is due to the thread its running on, if I despatch the request on the same thread that the managed object was created on it works perfectly.
So why is it in class 1. i have to ensure that the request is on the correct thread but in class 2. It just works, or is it just pure luck. Is there a recommended and documented approach to threads and core data?
Thanks