Xcode/Swift 'Filename Used Twice' Build Error

Xcode/Swift 'filename used twice' build error

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

File name used twice Xcode

This is most often bugs in Xcode where it gets confused about generated files (I literally ran into this exact problem this morning....)

The solution generally is to close Xcode, delete DerivedData, and reopen Xcode.

DerivedData is in ~/Library/Developer/Xcode/DerivedData/. You can remove the whole directory, or just the subdirectory related to your project.

"Delete DerivedData" is an incredibly common solution to Xcode problems, and has been for years. Most of us have some kind of alias to simplify it. This is mine:

alias cdd='cd ~/Library/Developer/Xcode/DerivedData/'

filenames are used to distinguish private declarations of the same name' error

The issue is happening because of the Xcode automatic subclass generation feature.

According to What's New In Core Data

Xcode automatic subclass generation


Xcode now supports automatic generation of NSManagedObject subclasses
in the modeling tool. In the entity inspector:

  • Manual/None is the default, and previous behavior; in this case you
    should implement your own subclass or use NSManagedObject.
  • Category/Extension generates a class extension in a file named like
    ClassName+CoreDataGeneratedProperties. You need to declare/implement
    the main class (if in Obj-C, via a header the extension can import
    named ClassName.h).
  • Class Definition generates subclass files named
    like ClassName+CoreDataClass as well as the files generated for
    Category/Extension.

The generated files are placed in DerivedData and
rebuilt on the first build after the model is saved. They are also
indexed by Xcode, so command-clicking on references and fast-opening
by filename works.



So for fixing your issue, you need to set the Codegen field value to Manual/None as shown below:
Core Data Codegen

How can I have 2 files with the same name in my swift project?

You cannot name the files the same. The solution is to include namespaces in filenames, instead of relying on folder structure.

So in your case, the file names would be:

directory1.A and anotherdirectory.A.

Xcode 10 Error: Multiple commands produce

The issue might be occurring because of multiple Plist or other files within App-

Solution -> Open target -> Build phases > Copy Bundle Resources and remove info.plist from there.

Sample Image

Note: If you have developed a watch app too then you will have to remove the plist from the watch and watch-extension too.

Xcode 10 Error: Multiple commands produce

The issue might be occurring because of multiple Plist or other files within App-

Solution -> Open target -> Build phases > Copy Bundle Resources and remove info.plist from there.

Sample Image

Note: If you have developed a watch app too then you will have to remove the plist from the watch and watch-extension too.

Xcode build error - Multiple commands produce .o, Target 'ProjectCoreData' has compile command for Swift source files listed twice

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:

Picture with solution



Related Topics



Leave a reply



Submit