invalid redeclaration in auto code generate NSManagedObject Subclass Swift 3

Summer Ji picture Summer Ji · Oct 31, 2016 · Viewed 15.1k times · Source

Using Version 8.1 of Xcode.

Create an entity named "MapRegionObject" in .xcdatamodeld file.enter image description here

Using auto code generator, click Editor on the navigation bar -> create NSManagedOject Subclass...

Got two files : MapRegionObject+CoreDataClass.swift and MapRegionObject+CoreDataProperties

Errors in two files showing in the screenshot: MapRegionObject+CoreDataClass.swift enter image description here

MapRegionObject+CoreDataProperties enter image description here

Please help me fix this bugs, thank you so much!

Answer

Kamillpg picture Kamillpg · Nov 2, 2016

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.