CoreData MagicalSave Error

I have a very simple method for creating an object.

NSManagedObjectContext *localContext = [NSManagedObjectContext MR_defaultContext];

NSDate *today = [NSDate date];

NSInteger dayID = [[[self periodFormatter] stringFromDate:today] integerValue];

CDDay *dDay = [CDDay MR_createInContext:localContext];

dDay.dayID = @(dayID);

[localContext MR_saveToPersistentStoreAndWait];

That's all he does, he works with all my unit tests, stress tests and automation exams on the iPhone 3,4 and 5, but when I get to the App Store when 100k + users install it, I get about 500 crashes from of this method.

I tried both in the main thread and in the background thread, the same problem. It only takes a few ms, and it is called only once.

Here is a log from a thread that breaks

1    libobjc.A.dylib     objc_msgSend + 5
2    libobjc.A.dylib     objc_object::sidetable_release(bool) + 172
3    libobjc.A.dylib     (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 356
4    CoreFoundation  _CFAutoreleasePoolPop + 16
5    Foundation  -[NSAutoreleasePool drain] + 120
6    CoreData    -[NSManagedObjectContext save:] + 942
7    ******  __70-[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:]_block_invoke3 (NSManagedObjectContext+MagicalSaves.m:64)
8    CoreData    developerSubmittedBlockToNSManagedObjectContextPerform + 86

I know that MR had problems with nested contexts, but this is due to the default context. Looks like I have to get rid of MR.

+3
source share

All Articles