Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode build error - Multiple commands produce .o, Target 'ProjectCoreData' has compile command for Swift source files listed twice

Tags:

xcode

swift

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 
like image 291
Joe Avatar asked Nov 29 '18 21:11

Joe


People also ask

Why is XCode not working on my project?

To elaborate a bit: This error is happening because Xcode 10's new build system is better at catching project configuration issues. Issues like these can sometimes cause subtle problems with your build, so it's good to fix them. – Rick Ballard Jun 6 '18 at 17:39

How to remove build phases from a project in Xcode?

Solution 1:In Xcode, go to File ➼ Project/Workspace settings.➼ Change the build system to Legacy Build system. Solution 2 :Open target ➼ Build phases ➼ Copy Bundle Resources ➼ remove info.plistfrom there.

How to find the root cause of Swift source files not compiling?

1) Target ' MyApp ' (project ' MyApp ') has compile command for Swift source files 2) Target ' MyApp ' (project ' MyApp ') has compile command for Swift source files The root cause can be seen by expanding the Compile Swift Source Filessection of the Build Transcript. For example:

How to change the build system in Xcode?

Try this Its Working : In Xcode, go to File->Project/Workspace settings. Change the build system to Legacy Build system. Share Follow answered Sep 13 '18 at 6:52 Akash PatelAkash Patel 32733 silver badges22 bronze badges 1 3


2 Answers

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

like image 158
IBAction Avatar answered Sep 22 '22 16:09

IBAction


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

like image 40
jeet.chanchawat Avatar answered Sep 22 '22 16:09

jeet.chanchawat