magicalpanda/MagicalRecord — Issue #110: Reset all managed object contexts in all threads
Author: idpaterson
Created: 2011-12-13 15:59:24+00:00
State: open

Our app requires a full reset capability to allow a tester to reset the app, without closing it, to essentially the same state it would be in after an install. Part of that process is rather harsh - we delete the main CoreData sqlite store.

Unfortunately, on some resets a thread is used such that the existing cached context for that thread is no longer valid. This allows old data to be returned from memory which can have a multitude of consequences. I would like to propose `+[NSManagedObjectContext resetContextForAllThreads]`

That method could be implemented by incrementing a static version number and also storing the current version number in the `threadDictionary`. Any call to `+ [NSManagedObjectContext contextForCurrentThread]` would validate against the current version number and generate a new context if it is outdated.

Is this something that would be useful for anyone else, or worth adding to the project? We will be implementing the solution described above since it is a fairly simple workaround, but if anyone else has a better idea or knows of a way to avoid this problem, we're all ears.