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.


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


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