invalid redeclaration in auto code generate NSManagedObject Subclass Swift 3 invalid redeclaration in auto code generate NSManagedObject Subclass Swift 3 ios ios

invalid redeclaration in auto code generate NSManagedObject Subclass Swift 3


In Xcode 8.1, before using the auto code generator, you must select the entity in your data model:

Entity

Then go to the Data Model Inspector tab:

Data Model Inspector

Under "Codegen" select "Manual/Node"

After that you could create a NSManagedObject subclass without errors.


Alternatively, if you have already used 'Class Definition', you can go into your existing .xcdatamodeld file and set all current entities to 'Manual/None' under Codegen. Make sure to save your project (File -> Save), delete your existing Derived Data, clean the project, and then build. Resolved it for me without having to re-make my whole model.


I found this whole thing to be very confusing. You really do need to understand what's new in CoreData. Basically, the default is to automatically generate the class and the extensions for you in a place called "DerivedData" that's buried in ~/Library/Developer/Xcode/DerivedData where these classes and their extensions live, outside of your code source. Personally, not being able to open and look at them is weird to me, but something to get used it.

Basically, if you have an entity called "AppSettings" in your CoreData model, you can just use it without needing to generate the code yourself. If you want the code in your project, then set the Codegen property on the entity to Manual/None. Then do what you did before: Editor->Create NSManagedObject classes, etc. The files will wind up in your project.

The good news is that if you want to make custom extensions, just do that in your project. Xcode will blend the generated files, from their other place outside your project directory, with the files in your project directory.


1) clean the project (cmd + shift + K)

2) In the "data model inspector" for every created Entity set attributes for Class just as in the screenshot below

screenshot

3) Generate code again (Editor -> create NSManagedObject Subclasses)

After that everything should work fine.