Xcode build error - Multiple commands produce .o, Target 'ProjectCoreData' has compile command for Swift source files listed twice
Solution 1
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:
Solution 2
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.
Related videos on Youtube

Comments
-
Joe 6 months
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
-
NivDid you try cleaning your build folder? Xcode > Product > Clean Build Folder
-
-
Joe about 4 yearsThanks, why does this work? Or why does the default not work?
-
IBAction about 4 yearsBecause 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.
-
Joe almost 4 yearsI'd assume "Class Definition" shouldn't be a default setting.
-
Tony about 2 yearsThis happened to me when Codegen was = 'Class Definition', yet I also generated NSManagedObject subclass from Editor menu.