Xcode build error - Multiple commands produce .o, Target 'ProjectCoreData' has compile command for Swift source files listed twice - 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

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:

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.

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.

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

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

Related

Why it compiles with different type?

Error:
IL2CPP error for type 'Namespace.SubNamespace.MyClass/<MyIEnumeratorFunc>d__20' in assembly 'Path\MyUnityProject\Temp\StagingArea\Data\Managed\VisualStudioSolutionName.dll'
Additional information: Interface System.Collections.Generic.IEnumerator`1<System.Object> method T System.Collections.Generic.IEnumerator`1<System.Object>::get_Current() not implemented on non-abstract class Namespace.SubNamespace.MyClass/<MyIEnumeratorFunc>d__20
Unity expect System.Collections.IEnumerator and I try to use IEnumerator:
I tried to write directly
private System.Collections.IEnumerator MyIEnumeratorFunc(){}
I tried to remove
using System.Collections.Generics;
and append it to each List/Dictionary entry
Everything works in Editor, but I get error I described above:
Seems like it tries to use System.Collections.GENERICS.IEnumerator.
Also, the error disappears if I use source code (not .dll)
Also, you can reproduce it by creating .dll with any IEnumerator/async function (even empty) and build for iOS.
The problem was in Project name.
Solution is
Right mouse click on Project name (not solution name) in Solution Explorer.
Properties
"Application" tab
Assembly name -> set to the same to .dll file name (without ".dll")

How to remove a form from a unit while keeping the unit in the project?

I use Delphi 7 and I encountered a very annoying thing. One of my projects has gone quite large and a form I used in one of the units became obsolete. I decided to get rid of it. It seems I can't. The IDE always asks for .dfm file, no matter what i tried (and I think i was very thorough).
Here's what I did:
First, I used the IDE's Remove from Project to remove the whole thing from the project. Then I commented out all sections that used anything in that unit and compiled, bulit and ran the project. It went without any errors or warnings. I saved all files and closed the Delphi IDE, started up a Notepad and removed the form's declaration from the unit, then deleted every associated file, except the .pas (with this, it became like any other regular unit).
Then I searched every file in the project's folder with Total Commander to see if any of them contained the name of the removed unit. None did.
I started Delphi and loaded the project.
With this I felt satisfied and added the unit's name to the uses list and pressed Compile.
IT STILL LOOKS FOR THE DAMNED DFM!!
If someone knows, please explain this to me. What did I miss?
If the compiler is looking for the .dfm file it will be because the compiler is including a unit that contains this:
{$R *.dfm}
That is what tells the compiler to link the .dfm file with the same name as the unit.
It seems likely that you still refer to the unit somewhere in your project. The compiler must be finding either a .pas file or a compiled .dcu file for your unit. Search for all files named <UnitName>.pas and <UnitName>.dcu. Remove these files. Then you will encounter compiler errors whenever you have code that attempts to use those units. Deal with those by removing the unit from the uses clause that names it. Then you should be done.

EF broken after update database. A namespace cannot contain members such as fields or methods

I have researched this topic and pulled up a couple of hits that I thought might have helped me. So far I am still pulling out my hair over here because everything was fine until I added a field to a table in Azure and then tried to update my model.
Here's a short sitrep of what the problems have been and what I have done to solve them.
Problem 1
Compiling transformation: Metadata file 'C:\Program Files\VS2013\Common7\Tools..\IDE\Microsoft.Data.Entity.Design.dll' could not be found
Compiling transformation: Metadata file 'C:\Program Files\VS2013\Common7\Tools..\IDE\EntityFramework.dll' could not be found
I solved the problem by changing my global environment variable in advanced system properties to the correct location of these files, which in my case was : F:\Program Files (x86)\Common7\IDE
This is probably due to the fact that I just installed VS 2013 ultimate on my F drive; however, I have been developing on it successfully now for a week and never had a problem until now.
After this I run into problem 2:
Problem 2
A namespace cannot directly contain members such as fields or methods C:\Users\Adrian.Campos\Documents\Visual Studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\Model1.cs 1 1 ConsoleApplication2
As you can see the problem is arising from my Model1.cs class. My .edmx file is named model1 (fyi)
I found some links that weren't of help to me since my error is coming from a different source than that of the links.
VS2012: My Entity Framework model doesn´t get included to my project output using InstallShield
A namespace cannot directly contain members such as fields or methods.
A namespace cannot directly contain members... + Type or namespace definition, or end-of-file expected errors
That last link seemed the most promising; however, it did not fix my problem. What I do not understand is how in the world did everything just blow up after I updated my model?
Has anyone else experienced this and fixed it?

Duplicate Symbol Error for architecture i386

I got this error when i tried to build:
"duplicate symbol __Z8ERRCHECK11FMOD_RESULT in:
/Users/codemenmini2012-2/Library/Developer/Xcode/DerivedData/MagicSleepFullVersion-agxulkdijnxbqmbuigucmrczufyw/Build/Intermediates/MagicSleepFullVersion.build/Debug-iphonesimulator/MagicSleepFullVersion.build/Objects-normal/i386/MagicSleepViewController.o
/Users/codemenmini2012-2/Library/Developer/Xcode/DerivedData/MagicSleepFullVersion-agxulkdijnxbqmbuigucmrczufyw/Build/Intermediates/MagicSleepFullVersion.build/Debug-iphonesimulator/MagicSleepFullVersion.build/Objects-normal/i386/MagicSleepViewControllerIpad.o
ld: 1 duplicate symbol for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)"
How to solve this guys?
The error may occur when you copy and paste the contents of one file to another file with its interface name which means two classes with same interface name.
In your code you have two different files with the same Interface name.
For me this error happened because I was dumb enough to copy the whole folder of a downloaded lib to the project and there was a demo project inside it. So I had two main.m files. Hope this helps anyone!
In my case I had accidently imported .m file instead if .h file. Hope it helps someone for this kinda silly mistake.
when you create bool variables with same name in two different classes then this error comes.
"duplicate symbol __Z8ERRCHECK11FMOD_RESULT in"
so check your both classes
MagicSleepViewController.m and
MagicSleepViewControllerIpad.m.
for same bool variables.
Change the bool variable name, your problem will solve.
Looks like you have at least one (probably more) symbol (or methods, functions, etc.) that's duplicated between MagicSleepViewController.m and MagicSleepViewControllerIpad.m.
You need to either 1) change the names of one set of duplicated methods or 2) figure out a way to merge MagicSleepViewController.m & MagicSleepViewControllerIpad.m so the same code will work on both iPhones and iPads (e.g. using run time conditionals or whatever to determine what kind of device your code is currently running on).
I had #defines placed in two files that were exactly the same... DOH.
For me, a search in the finder for the named duplicates has helped.
The problem in my case was caused due to multiple references in the "Compile Sources". So I deleted one from Project->Build Phases-> Compile Sources.

prefix attribute must be followed by an interface or protocol + NSManagedObject Subclass

So I get the compile error "prefix attribute must be followed by an interface or protocol" in an xcode generated NS Managed Object subclass. The error is matched to the line #class AnswerSet, Section, SurveyStyle; and then all lines where these objects are used. The error seemed to have come at random but I am fairly convinced it originated from deleting some of the generated classes and then re-building them.
The code in the class is irrelevant as it worked before and compiles when I copy it into a new project.
So far I have tried deleting them all again and rebuilding. Cleaning the project. Restarting ect.
My last resort will be to copy everything across into a new project file and/or refactor what I have but I'm hoping someone can suggest something to save me from that!
Edit: Just attempted to rename the entity/class of the offending file. Xcode hanged and I force quit it. Renamed the file and refactored. Ended up with the same issue.
Turns out the error was a result of a stray character outside the comments at the top of a class. Not sure why it didnt pick it up but it took a long time to track it down!
Add The piece of code in implementation file(.m)import
AVFoundation/AVFoundation.h