Unable to find specific subclass of NSManagedObject Unable to find specific subclass of NSManagedObject ios ios

Unable to find specific subclass of NSManagedObject


Update for Xcode 7 (final): Prepending the module name to the class (as in Xcode 6 and early beta releases of Xcode 7) is no longer necessary.The Apple documentation Implementing Core Data Managed Object Subclasses has beenupdated accordingly.

The Data Model inspectorhas now two fields "Class" and "Module" for an entity:

enter image description here

When you create a Swift managed object subclass for the entity, the"Module" field is set to "Current Product Module", and with this settingcreating instances works both in the main application and in unit tests.The managed object subclass must not be marked with @objc(classname) (this was observed in https://stackoverflow.com/a/31288029/1187415).

Alternatively, you can empty the "Module" field (it will show "None") and mark themanaged object subclasses with @objc(classname) (this was observed in https://stackoverflow.com/a/31287260/1187415).


Remark: This answer was originally written for Xcode 6.There were some changes in the various Xcode 7 beta releases withrespect to this problem. Since it is an accepted answer with manyupvotes and links to it, I have tried to summarize the situationfor the current Xcode 7 final version.

I did both my own "research" and read all the answers to both this question and the similar questionCoreData: warning: Unable to load class named. So attribution goes to all of them, even if I don'tlist them specifically!


Previous answer for Xcode 6:

As documented in Implementing Core Data Managed Object Subclasses, you have toprefix the entities class name in the Class field in the model entity inspector with the name of your module, for example "MyFirstSwiftApp.User".


Just as a side-note. i had the same issue. And all i had to do was add @objc(ClassName) in my class file.

Example:

@objc(Person)class Person { }

And that solved my issue.


The accepted answer to this question helped me resolve the same issue but I had a caveat that I thought would be helpful to others. If your project (module) name has a space in it you must replace the space with an underscore. For example:

Entity: MyEntityClass: My_App_Name.MyClass