Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode/Swift 'filename used twice' build error

I'm new to Swift and am struggling with an error after I have (possibly) correctly installed a 3rd party framework via CocoaPods.

The error is as follows.

<unknown>:0: error: filename "MainController.swift" used twice: '/Users/myname/Desktop/ProjectName/ProjectName/Controllers/MainController.swift' and '/Users/myname/Desktop/ProjectName/ProjectName/Controllers/MainController.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 

As far as I can gather from other forums and seemingly obvious is that I have to remove one of the files being used twice. However I can't see where they would be installed twice. If I remove the file from the /Controllers folder the error becomes 'file not found' etc.

So my question is, where would these conflicting files be located and how do I safely remove one of them? Or is it more that there is only one file but it is being used twice - in which case how do I stop that?

Many thanks.


Ok I feel that comments are getting lost so am clarifying here to see if can trigger an answer as not been able to build and run this since yesterday.

I now have only the swift files in the Pods->Pods/MainController folder.

When I build I get a file not found. However the file it is looking for is in App->Controllers folder which is where I deleted it from. If I put the file in there I get the 'used twice' error.

So how do I stop it trying to find the file in the Controllers and look for it in the Pods?

Thanks

like image 478
RobertyBob Avatar asked Jan 17 '16 12:01

RobertyBob


2 Answers

Check the file is not included twice in the target's "Build Phases" "Compile Sources" settings. It can happen when you merge project.pbxproj.

like image 184
franck Avatar answered Oct 08 '22 00:10

franck


If this is core data related and you are not having Xcode generate the entities for you at build time (you created them manually yourself), and you are experiencing this issue, chances are that you didn't check update the entity in the .xcdatamodelld file. What happens is that Xcode will create a duplicate class of your existing class, since you told Xcode to generate the entity at runtime.

In the Data Model Inspector change "Module" to "Current Product Module", and "Codegen" to "Manual/None".
enter image description here

like image 21
Josh O'Connor Avatar answered Oct 08 '22 01:10

Josh O'Connor