I have a problem with core data in IOS 8. Whenever I want to use the insertNewObjectForEntityForName
method, I get the
Class not found,
There is a similar answer to this question. In my case I was using Objective-C and doing this got rid of this error in the console.
I found the answer here: Unable to find specific subclass of NSManagedObject
You can empty the "Module" field (it will show "None") and mark the managed object subclasses with @objc(classname)
This fixed it for me.
When none of the solutions worked for me, I deleted the existing NSManagedObject and created a new one. If you need any code from the previous object remember to take a backup, and later copy that into the new NSManagedObject class. Hope this helps someone.
When using Swift the error could still appear also if the source file is included in the Build Phases > Compile Sources the error
unable to load class named '...' for entity '...'. class not found, using default nsmanagedobject instead.
To solve this you could prefix the specific model class in the model inspector (here with MyApp). See also the documentation.
Our you can add objc(Person)
before your swift class declaration
@objc(Person)
class Person: NSManagedObject {
...
}
That error means that you've configured a custom class name for the entity type in the model editor, but that the class does not exist at run time. Core Data falls back on creating a generic NSManagedObject
using the entity type.
Assuming that the class file actually exists somewhere, the problem is that you're not including that file in the app target in Xcode. Since Xcode supports multiple targets, projects, etc, it doesn't automatically include every source file in every build. Add the Core Data subclass file(s) to the app target and this error should go away.
As of Xcode 7 there is a Module
property that you can set to Current Product Module
(it appears automatically), so you don't need to use prefixes.
If you are using Xcode 7 beta the actual solution is removing the @objc(Person)
. Must be a bug in the template that is used for generating entity classes in Xcode 7 beta.