I just simply created a demo project with Core Data.
I created an entity Userinfo
in my data model. Now I created a NSManagedObject
subclass of this entity.
Xcode autogenerated these 4 classes.
Now when I build the project it throws this error:
I have done everything I know to remove the error of duplicacy but nothing helped.
I think its a Xcode bug. Please help.
You are generating files which have already been generated for you by Xcode and thus get duplicate declarations. Details about this feature (new in Xcode 8) can be found in this WWDC video.
Two possible fixes:
1) Use the Xcode generated
ManagedObject
subclasses (the recommended, modern approach)Codegen
toClass Definition
in your.xcdatamodel
for all entitiesModule
is empty ("Global Namespace" in light gray) (workaround an Apple bug, see this answer)Note:
Never add the automatically generated files to your project. Even you do not see the generated files in your project, Xcode has a reference to it, so you are able to write extensions and such. For instance:
Also, you can command+click to the generated file within Xcode.
2) Trigger subclass generation manually (a rather paranoid but bullet-prove approach, ignoring the new Xcode features)
Codegen
toManual/None
in your.xcdatamodel
for all entitiesNSManagedObject
subclasses (in "Editor" menu)