Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class not found, using default NSManagedObject instead

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.

like image 818
Dániel Nagy Avatar asked Sep 16 '14 12:09

Dániel Nagy


5 Answers

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 {
   ...
}
like image 168
H6. Avatar answered Oct 20 '22 05:10

H6.


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

like image 38
FranMowinckel Avatar answered Oct 20 '22 03:10

FranMowinckel


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.

like image 17
C0D3 Avatar answered Oct 20 '22 05:10

C0D3


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.

like image 15
Tom Harrington Avatar answered Oct 20 '22 05:10

Tom Harrington


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.

like image 9
Samuel Mellert Avatar answered Oct 20 '22 03:10

Samuel Mellert