Xcode/Swift 'filename used twice' build error

Multi tool use
Multi tool use


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




7 Answers
7



Try to search, if you have added same ViewController - MainController.swift twice.


MainController.swift



If not, then search class MainController in codebase.


class MainController



Regarding Pods, it is preferred to use all Pods as frameworks,



So try using 'use_frameworks!' in your Podfile, and then from terminal reinstall the pods "pod install".


'use_frameworks!'


Podfile


pod install





Many thanks Ankit. By using the search for classes I have found 2 instances - one in Pods and one in the Project. Since the one in the project is the code for the ViewController, can I assume I delete the one in the Pods (the whole MainController folder or just the swift file within)?
– RobertyBob
Jan 17 '16 at 13:43






To clarify - I have duplicates of the Swift files (and therefore the classes). One is within the main App in /Controllers folder alongside all other Swift files. The other is with a Pods App->Pods folder. The Pods App seems to contain the other 3rd party folders. If I delete the Swift file in the main app i get file not found error but have a feeling that this is the one needing removed. So do I need to point something at the Pods folder instead?
– RobertyBob
Jan 18 '16 at 13:09





can you refer, which pod file you are using. Actually file name either in Pods or in local bundle should not have same name, because during compile time, it will give error due to class reference. Here is one of the issue, which other developers have also found: github.com/CocoaPods/CocoaPods/issues/4166
– Ankit Thakur
Jan 18 '16 at 16:21





There is no longer an issue with duplicate classes since I removed the swift files from the main app files. The only location for the swift file is in Pods>Pods>PagingMenuController however the build keeps wanting to find it in the main app files and can't since I removed it. I've tried adding all sorts to the bridging header file but nothing stops it wanting to find the file in the /controllers folder of the main app
– RobertyBob
Jan 18 '16 at 16:35





ok this is my issue with this - I randomly found a reference to the /controllers/pagingmenucontroller file in the Build Phases>Compile Sources. This seemed to be a likely culprit so I removed it since the file doesn't exist..... Now my bridging header fails cos RestKit.h can't be found even tho this has never ever been an issue before.
– RobertyBob
Jan 18 '16 at 17:45



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





This was exactly the problem for me.
– Will Y
Oct 12 '16 at 2:33





Exact solution for me too!
– Okan Kurtuluş
Nov 21 '16 at 19:19





thanks, this worked for me too
– grgmo
Feb 9 '17 at 13:00





Perfect. I got into the issue after rebasing. Thanks!
– itsdamslife
Feb 27 '17 at 15:24





This is the mostly occuring problem. Same file with different path in merge can cause this problem.
– mkeremkeskin
Mar 21 '17 at 7:23



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





god bless your soul
– Artem Misesin
Jun 28 '17 at 11:49





I just had to change the name in the Name field. I don't know why there were two Entities with same names here. And then had to do a full clean and rebuild.
– zeeshan
Mar 30 at 13:59



The main idea is... yes, check for duplicated classes. But in my case I had none. I had a big project, added WatchKit, lots of stuff and at some point I had a "duplicated" class. I removed the duplicate but the problem remained. To fix it I did this:





Thank you ! Double entry in Project Settings>"Build Phrases" was the issue.
– Nikhil Mathew
Jul 11 '16 at 23:05





Glad it worked, XCode bugs are insane! @NikhilMathew
– Josh
Jul 12 '16 at 9:49





Thanks . It really worked,
– Aks
Mar 19 '17 at 23:20





Glad it was useful, upvote if it worked! @Aks
– Josh
Mar 20 '17 at 9:12



This can be in your project.pbxproj when you make merge with github or similar tool.



This can be fix opening the project.pbxproj in your favorite text editor and removing the duplicates declarations.



Hope that fix your problem.



I came across this issue by remove the used twice file from Compile Sources as below image. Selected the file, and click the -. Then clean and build.



enter image description here



I would add on to Josh O'Conners answer in that making the changes he recommended was the root of my problem. I did have to clean the build folder by hitting shift-option-command-k to complete the fix.





My new favorite keyboard shortcut.
– Sebastian Roth
Feb 13 '17 at 9:38






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

p,PnhK,2Y,EAanjKZpLTMp,rBrkL14BxW6 kt8H,HQOfDv 0Al8zTr8ik
mO D54HfR9oAOME34a,ULHE,Dgk5nKL5xsDYqFT6j2dH7xAPGPWwSv

Popular posts from this blog

Delphi Android file open failure with API 26

.

Amasya