I use MagicalRecord for my CoreData store. I have a statement that is generating multiple crashes by different users when this statement is executed:
PreferenceData *prefDataFound = [PreferenceData MR_findFirst];
The error is:
+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'PreferenceData'
coming from this sequence of calls (from Crashlytics):
1 libobjc.A.dylib objc_exception_throw + 30
2 CoreData +[NSEntityDescription entityForName:inManagedObjectContext:] + 104
3 SalonBook NSManagedObject+MagicalRecord.m line 91
+[NSManagedObject(MagicalRecord) MR_entityDescriptionInContext:]
4 SalonBook NSManagedObject+MagicalRequests.m line 19
+[NSManagedObject(MagicalRequests) MR_createFetchRequestInContext:]
5 SalonBook NSManagedObject+MagicalFinders.m line 79
+[NSManagedObject(MagicalFinders) MR_findFirstInContext:]
6 SalonBook NSManagedObject+MagicalFinders.m line 86
+[NSManagedObject(MagicalFinders) MR_findFirst]
7 SalonBook SubViewGrid.m line 37
-[SubViewGrid drawRect:]
All of this indicates to me that there is no valid context for the MR_findFirst call; oher than using *MR_findFirstWithPredicate:* (for which I have no predicate, I just want the first and only record), what can I do to fix this?
You can call
PreferenceData *prefDataFound = [PreferenceData MR_findFirstInContext:context];
with your current context, instead of relying on Magical Record to determine the current context magically.