Question

I have this code where I'm trying to get all records for a certain key:

//  if the apptObject.aApptKey is nil, skip it...
if(apptObject.aApptKey == nil)
    continue;  //  go to beginning and try again 

    //  using apptObject.aApptKey, get the client's name
NSPredicate *predicate =  ([NSPredicate predicateWithFormat:@"(aClientKey = %@)", apptObject.aApptKey]);
    clientInfo = [ClientInfo MR_findAllWithPredicate: predicate];

The problem is I'm getting this error (courtesy of Crashlytics):

Fatal Exception: NSInvalidArgumentException +entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'ClientInfo'

Either don't understand what the error message is telling me, or I don't understand how it could happen if I'm testing for nil prior to the MR_findAll. Note that the 'keys' in question are exactly the same, I'm just using the appointment key to get the client's name.

Can someone please explain how this could happen?

Was it helpful?

Solution

(From my comment:) The error message has nothing to do with the predicate. It tells you that the NSManagedObjectContext is nil.

A possible problem could be the MR_contextForCurrentThread method which is deprecated and should not be used anymore. The reason is that it assumes a unique thread for each managed object context. This is no longer true with the new MOC concurrency types which run on GCD queues. Compare https://stackoverflow.com/a/20536335/1187415.

Better use MR_defaultContext or pass the context from one view controller to the next.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top