14
votes

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.

7

7 Answers

14
votes

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.

31
votes

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.

enter image description here

Our you can add objc(Person) before your swift class declaration

@objc(Person)
class Person: NSManagedObject {
   ...
}
30
votes

This is an updated version from the answer provided from @High6

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.

Xcode Core Data editor

15
votes

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)

enter image description here This fixed it for me.

9
votes

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.

0
votes

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.

0
votes

Having this issue with SPM.

My model is being loaded from Bundle.module. But none of the classes can be found when trying to access them at runtime