magicalpanda / MagicalRecord

Super Awesome Easy Fetching for Core Data!
Other
10.8k stars 1.79k forks source link

After updating, MR_findAllWithPredicate now causing crash #1108

Open AndrewHartAR opened 8 years ago

AndrewHartAR commented 8 years ago

I had this code at the start of my application, which worked fine before:

MagicalRecord.setupCoreDataStack()
let context = NSManagedObjectContext.MR_context()
let predicate = NSPredicate(format: "sendStatus = \(MessageSendStatus.Sending.rawValue)")
let messages = Message.MR_findAllWithPredicate(predicate, inContext: context) as! Array<Message>

I then handle those messages.

Upon updating, the code changed as follows:

MagicalRecord.setupClassicStack()
let context = NSManagedObjectContext.MR_context()
let predicate = NSPredicate(format: "sendStatus = \(MessageSendStatus.Sending.rawValue)")
let messages = Message.MR_findAllWithPredicate(predicate, inContext: context) as! Array<Message>

Only the first line changed. But now when I run it, I get a crash on that last line:

*\ Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSPersistentStoreCoordinator for searching for entity name 'Message''

I tried changing the context declaration to NSManagedObjectContext.MR_mainQueueContext(), just for testing it out, but it still produced the same error. Removing the inContext: argument from that last line works, but I'd guess it's not advised, as it'd then just cause problems:

What am I doing wrong?

hardikdevios commented 8 years ago

use this context NSManagedObjectContext.MR_defaultContext()

AndrewHartAR commented 8 years ago

@hardikdevios that's dependent on me being on the main thread.

pronebird commented 8 years ago

@ProjectDent enable debugging for MagicalRecord and make sure you model is loaded.