Invalid redeclaration on CoreData classes

I am working with CoreData, on an entity called "RoleName".

The problem is: I click on "Create NSManagedObject subclass" from within my model, and so it automatically creates the classes for my entity.

However, on the declaration of the class, I get this error:

Invalid redeclaration of "RoleName"

even though I don't have any other class with the same name.


Solution 1:

This is because Xcode handles all that by itself. I felt it like a bit of trouble as the auto generated classes don't have all my properties.

So follow these steps to get this as it used to be:

  • Delete what ever classes you already made for core data.
  • Set class.Module as Current Product module enter image description here

  • Set Class.codegen as Manual/None

enter image description here

  • Now select your entity and create NSmanagedobject subclass enter image description here

  • You are all set

Solution 2:

From Apple : Whats new in Core Data

Xcode automatic subclass generation

Xcode now supports automatic generation of NSManagedObject subclasses in the modeling tool. In the entity inspector:

Manual/None is the default, and previous behavior; in this case you should implement your own subclass or use NSManagedObject. Category/Extension generates a class extension in a file named like ClassName+CoreDataGeneratedProperties. You need to declare/implement the main class (if in Obj-C, via a header the extension can import named ClassName.h). Class Definition generates subclass files named like ClassName+CoreDataClass as well as the files generated for Category/Extension.

The generated files are placed in DerivedData and rebuilt on the first build after the model is saved. They are also indexed by Xcode, so command-clicking on references and fast-opening by filename works.

You don't need to manually create subclasses for NSManagedObjects.

I would suggest that you delete the files that you created with NSManagedObjects (Move them to Trash) and go to every entity in the DataModel Inspector under Codegen select : Manual / None and create than the Subclasses.