Xcode/Swift 'filename used twice' build error

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


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


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


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

If not, then search class MainController in codebase.

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".