Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

executeFetchRequest:error: A fetch request must have an entity

I had a project that was working fine. It had "Core Data" checked, and had the data model all set up. I only started adding a couple entities and properties tonight. When I try to run my app now, it won't even load. It just crashes on me.

Here's the error:

'NSInvalidArgumentException', reason: 'executeFetchRequest:error: A fetch request must have an entity.'

I'm really scared because I don't have a backup of this and if I can't get it working I don't know what I'll do. :)

Thanks in advance!

EDIT: I got fed up with my data, so I just copied a new blank xcdatamodel to my project and I'm going to start fresh. Thanks for the help!

like image 968
sudo rm -rf Avatar asked Nov 12 '10 04:11

sudo rm -rf


3 Answers

My issue is I didn't use the same name for Entity and Class. Trivial solution to fix it is by giving them the same name.

like image 179
syshen Avatar answered Nov 20 '22 15:11

syshen


If you are using MagicalRecored with Swift:

Make sure you use @objc directive in the Swift NSManagedObject subclass to make the class accessible to Objective-C code from the MagicalRecord library

@objc(MyEntity)
class MyEntity: NSManagedObject {
    @NSManaged var myAttribute: Int16
}
like image 21
Warif Akhand Rishi Avatar answered Nov 20 '22 15:11

Warif Akhand Rishi


After searching all over for a solution, what fixed it for me was doing a Clean/Build in Xcode.

Product->Clean, Product->Build, then try running it.

like image 14
Jake Stoeffler Avatar answered Nov 20 '22 16:11

Jake Stoeffler