invalid redeclaration in auto code generate NSManagedObject Subclass Swift 3
Solution 1:
In Xcode 8.1, before using the auto code generator, you must select the entity in your data model:
Then go to the Data Model Inspector tab:
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.
Solution 2:
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.
Solution 3:
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
3) Generate code again (Editor -> create NSManagedObject Subclasses)
After that everything should work fine.
Solution 4:
The problem is that you don't need to generate NSManagedObjectModel subclasses manually anymore. ref: https://forums.developer.apple.com/thread/48988
Xcode automatically generates classes or class extensions for the entities and properties in a Core Data data model. Automatic code generation is enabled and disabled on an entity by entity basis, and is enabled for all entities in new models using the Xcode 8 file format. This feature is available for any data model that has been upgraded to the Xcode 8 format. You specify whether Xcode generates Swift or Objective-C code for a data model using the data model’s file inspector. When automatic code generation is enabled for an entity, Xcode creates either a class or class extension for the entity as specified in the entity's inspector: the specified class name is used and the sources are placed in the project’s Derived Data. For both Swift and Objective-C, these classes are directly usable from the project’s code. For Objective-C, an additional header file is created for all generated entities in your model: The file name conforms to the naming convention 'DataModelName+CoreDataModel.h'.