I have a problem with core data in IOS 8. Whenever I want to use the insertNewObjectForEntityForName
method, I get the
Class not found, using default NSManagedObject instead.
Error message. I use objective-c, and I did not had this problem using IOS 7. Also could there be any problem because in my workspace there are two projects, one containing the core data relating code, and the other the UI.
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 {
...
}
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With