The current version of my application used an older version of MR (don't know the exact revision, but it was the pre MR_ prefix days),
All over the application I have code that used to look like this:
NSManagedObjectContext* context = [NSManagedObjectContext context];
that sits in a background operation. Upon updating to the current version of MR, I went through and updated everything to look like this...
NSManagedObjectContext* context = [NSManagedObjectContext MR_context];
but now I'm getting an
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Context already has a coordinator; cannot replace.'
when the setter is being called.
What has changed?
FWIW, Building on iOS5 SDK without ARC.
EDIT1 I realize now that there is now a MR_contextThatNotifiesDefaultContextOnMainThread helper... is this the new preferred way of doing things?
EDIT2 Moving everything to MR_contextThatNotifiesDefaultContextOnMainThread has fixed the initial problem.. but now I have random crashes with EXC_BAD_ACCESS...
Perhaps some information on what my operations are doing:
EDIT3 I went on a hunch this morning and took a gamble that the problem had something to do with ARC, so I went and took out
#define MR_USE_ARC __has_feature(objc_arc)
inside CoreData+MagicalRecord.h to force NO ARC operation...
This is probably not the way to be doing things, but it seems to have temporarily alleviated my problems...
EDIT 4 So it looks like MR_contextThatNotifiesDefaultContextOnMainThread helper doesn't seem to be working properly. The context it creates doesn't notify the main context at all. Workaround that I managed to get working is to do
NSManagedObjectContext *context = [NSManagedObjectContext MR_context]; //background context
[[NSManagedObjectContext MR_defaultContext] MR_observeContext:context];
only then I could get a proper merge to occur.
Strictly looking at the console log, if you call MR_save from a context returned by the helper, you never see the
Merging changes to *** DEFAULT *** context
Digging into the source reveals that depending on whether you are running in THREAD_ISOLATION_ENABLED or PRIVATE_QUEUES_ENABLED, you get some REALLY different things happening for the helpers/methods related to
having a context that notifies the main one...
I'm downgrading to 1.8 for now and seeing how far I can get the application to run with that...
I am seeing the same issue with the EXC_BAD_ACCESS
I posted a similar issue here: #141
Did either of you define an approach that works? Anthony, did you downgrade and get better results?
I haven't been working on the particular project for a while now, but at the time I believe we decided on a downgrade and things seemed to work out okay.
thanks, I'll put a downgrade on my list of things to try. I only require iOS 5, so I'm giving the iOS 5-only branch a try: https://github.com/magicalpanda/MagicalRecord/tree/iOS5-only
Same issue. What to do?