7

Good evening!

So I've been having some trouble understanding what the hell is going on while saving my data in Core Data. First of all, a quick question:

1) When should I be using the persistentStoreManagedObjectContext and when should I be using the mainQueueManagedObjectContext?! Right now, I always use the persistentManagedObjectContext, but I can see that a RestKit call "getObjectsPath", the object will have the mainQueueObjectContext. Why is that?!

Thanks!

abisson
  • 4,365
  • 9
  • 46
  • 68

1 Answers1

2

persistentStoreManagedObjectContext could be used to populate other another NSManagedObjectContext (e.g. for a background thread).

So unless your not leaving the main thread when accessing the object, use the mainQueueManagedObjectContext and you're on the safe site.

Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
flashfabrixx
  • 1,183
  • 9
  • 22
  • Noob question then: How should I know if I am leaving the main thread or not? – abisson Mar 24 '13 at 15:06
  • Unless your using `dispatch_async` or `NSOperation` and aiming to use a background thread, your save. In short: When you don't know if your using the background thread or not, your save ;) – flashfabrixx Mar 26 '13 at 10:01
  • Hey! I am still having some issue with this... I recently got into a problem where for some reason CoreData fails and so on... and I think it has to do with this. I was using persistent like this. https://dpaste.de/XDuc Should I use the main one instead and then do a SaveToPersistent? – abisson Mar 04 '14 at 23:55
  • Like mentioned [here](http://stackoverflow.com/questions/14472467/rest-kit-persistance-performance-issue-with-multiplie-mocs) ```saveToPersistentStore:&error``` is reserved to use with mainQueueManagedObjectContext. Try to use this context instead. – flashfabrixx Mar 05 '14 at 11:06