49

I am running xCode Version 10.1 (10B61), Mojave 10.14 (18A391)

Searching shows similar issue in Xcode 10 greater than a year ago, but no issues since then. The solution from last year seemed to be switching to legacy mode, but that doesn't work now. It appears the source code that is stored on my desktop is conflicting with code that is in 'DerivedData', I'm not sure why this would suddenly pop up so randomly.

I see this problem go away if I remove the last model added in Core Data. It seems to trigger when I add a relationship to another object. It's apparently random.

Any advice on how to fix this issue so I can develop?

Multiple commands produce '//Library/Developer/Xcode/DerivedData/ProjectCoreData-ehjvvgovpitmbcegzopwciptfafr/Build/Intermediates.noindex/ProjectCoreData.build/Debug-iphonesimulator/ProjectCoreData.build/Objects-normal/x86_64/Contact+CoreDataClass.o':

Target 'ProjectCoreData' (project 'ProjectCoreData') has compile command for Swift source files

Target 'ProjectCoreData' (project 'ProjectCoreData') has compile command for Swift source files

from the logs:

<unknown>:0: error: filename "Contact+CoreDataClass.swift" used twice: '/Users/<user>/Desktop/ProjectCoreData/Contact+CoreDataClass.swift' and '/Users/<user>/Library/Developer/Xcode/DerivedData/ProjectCoreData-ehjvvgovpitmbcegzopwciptfafr/Build/Intermediates.noindex/ProjectCoreData.build/Debug-iphonesimulator/ProjectCoreData.build/DerivedSources/CoreDataGenerated/ProjectCoreData/Contact+CoreDataClass.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
<unknown>:0: error: filename "Contact+CoreDataProperties.swift" used twice: '/Users/<user>/Desktop/ProjectCoreData/Contact+CoreDataProperties.swift' and '/Users/<user>/Library/Developer/Xcode/DerivedData/ProjectCoreData-ehjvvgovpitmbcegzopwciptfafr/Build/Intermediates.noindex/ProjectCoreData.build/Debug-iphonesimulator/ProjectCoreData.build/DerivedSources/CoreDataGenerated/ProjectCoreData/Contact+CoreDataProperties.swift'
<unknown>: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
Joe
  • 1,014
  • 1
  • 13
  • 28
  • 2
    Did you try cleaning your build folder? Xcode > Product > Clean Build Folder – Niv Nov 29 '18 at 21:30
  • Yes, also manually deleted the derived data folder. I can remove the object from core data, and it functions. It fails only when the relationship is added. – Joe Nov 29 '18 at 22:34

5 Answers5

182

The reason you see this error is because Core Data creates these files by default, but you can't see them in Project Navigator. Then you create a duplicate (in Editor/Create NSManagedObject Subclass). As a result you have your error.

According to What's new in Core Data here is a picture with the solution:

Picture with solution

Jeehut
  • 20,202
  • 8
  • 59
  • 80
IBAction
  • 2,131
  • 2
  • 9
  • 14
  • Thanks, why does this work? Or why does the default not work? – Joe Dec 10 '18 at 05:05
  • 17
    Because Core Data creates this files by default, but you can't see them in Project Navigator. Then you create a duplicate (in Editor/Create NSManagedObject Subclass). As a result you have your error. – IBAction Dec 10 '18 at 18:28
  • I'd assume "Class Definition" shouldn't be a default setting. – Joe Jan 03 '19 at 02:16
  • This happened to me when Codegen was = 'Class Definition', yet I also generated NSManagedObject subclass from Editor menu. – Tony Sep 27 '20 at 08:40
21

For future users : If you are using core data and If you copied entity using option+drag, then ensure that entity name and class name must be same. None of the solutions mentioned over internet worked for me. enter image description here

jeet.chanchawat
  • 5,842
  • 5
  • 38
  • 59
  • 1
    I copy+pasted several objects and they had the same class name but different entity names, which I didn't notice, and because of this, Xcode was returning several errors. Changing codegen to Manual/None fixed the problem, but this is the correct solution! Thanks! – amodrono Jan 05 '22 at 18:38
4

It happened to me after I dragged the coredata model and classes from another project, which generated duplicate files. If this is your case, go to TARGETS->Build Phases->Compile Sources, remove the duplicate files and it should be working again.

William Tong
  • 479
  • 7
  • 14
2

for me it was simple problem, i had 2 source files of the exact same name, just renamed one of them (only the swift file name) and the problem was gone

Shaybc
  • 2,628
  • 29
  • 43
0

To fix this I've to open the .xcdatamodeld using finder/show package content This image

and then repeat this operation with the .xcdatamodel. This option

After this I've opened the file (I use Sublime) Sublime Text locate the duplicate class name Duplicate Class Name, change it, save the file and build again. Like this