'filenames are used to distinguish private declarations of the same name' error

IosXcodeCore DataNsmanagedobject

Ios Problem Overview


I am getting this error on generating an NSManagedObject in Xcode 8.1 in Swift.

> :0: error: filename "DemoOne+CoreDataClass.swift" used twice: '/Users/Swasidhant/Desktop/demo again/DemoOne+CoreDataClass.swift' and '/Users/Swasidhant/Library/Developer/Xcode/DerivedData/demo_again-hiinrbwwbmyfbrbctsfdzvudkkuy/Build/Intermediates/demo again.build/Debug-iphonesimulator/demo again.build/DerivedSources/CoreDataGenerated/Model/DemoOne+CoreDataClass.swift' :0: note: filenames are used to distinguish private declarations with the same name :0: error: filename "DemoOne+CoreDataProperties.swift" used twice: '/Users/Swasidhant/Desktop/demo again/DemoOne+CoreDataProperties.swift' and '/Users/Swasidhant/Library/Developer/Xcode/DerivedData/demo_again-hiinrbwwbmyfbrbctsfdzvudkkuy/Build/Intermediates/demo again.build/Debug-iphonesimulator/demo again.build/DerivedSources/CoreDataGenerated/Model/DemoOne+CoreDataProperties.swift' :0: note: filenames are used to distinguish private declarations with the same name Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

I searched for this and got answers saying the file might be present twice in the project which is not my case. Another solution I came across was to remove the file from the build phase and add again. That too didn't work. Is it some build setting configuration mistake ? Or something else?

Here is the link with a demo project created with Xcode 8.1 and showing this problem:- https://www.dropbox.com/s/xwyzhshktb2hqe7/demo2.zip?dl=0

Ios Solutions


Solution 1 - Ios

The issue is happening because of the Xcode automatic subclass generation feature.

According to What's 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.


So for fixing your issue, you need to set the Codegen field value to Manual/None as shown below: Core Data Codegen

Solution 2 - Ios

This is what I did to fix this issue,

  1. Select your entity in the data model
  2. Set the Module to Current Product Module
  3. Leave the Codegen to Class Definition though Manual/None also works
  4. Select Editor > Create NSManagedObject Subclass

Solution 3 - Ios

May help someone, Go to project compile source delete the extra reference if any.

Solution 4 - Ios

Select code data model then select the Entity change the value of 'Codegen' to Manual/None.

It will work.

Solution 5 - Ios

The issue was due a second file named:"Extensions.swift" in my project.

After deleting the duplicate "Extensions.swift" the error got resolved. Your error message might tell you which file is duplicated.

Solution 6 - Ios

In my case Data Model (as example: MyCoreData.xcdatamodeld) was listed twice under Editor -> Create NSManagedObject Subclass... And here was reason why it was getting this type of error.

What I did:

  1. I did delete MyCoreData.xcdatamodeld file.
  2. Created another Data Model as example MyCD.xcdatamodeld.
  3. Checked is here duplicated Data Models in here: Editor -> Create NSManagedObject Subclass...
  4. Clean and later build for two times.

Solution 7 - Ios

It happened to me when I copied and renamed entity. It failed to rename the class, so do it manually.

Solution 8 - Ios

I just restart my Macbook and that clean my build folder. And it works like a charm!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSwasidhantView Question on Stackoverflow
Solution 1 - IosMidhun MPView Answer on Stackoverflow
Solution 2 - Iossuperm0View Answer on Stackoverflow
Solution 3 - IosNaveen ShanView Answer on Stackoverflow
Solution 4 - IosYogendra SinghView Answer on Stackoverflow
Solution 5 - IosDarkwonderView Answer on Stackoverflow
Solution 6 - IosRamisView Answer on Stackoverflow
Solution 7 - IosDisplay NameView Answer on Stackoverflow
Solution 8 - IosFirda SahidiView Answer on Stackoverflow