Filenames Are Used to Distinguish Private Declarations of the Same Name' Error

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

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

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.

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/'

CoreData NSManagedSubClass files generating duplicate files?

I think I found the solution but not sure why, so anyone that can elaborate would be appreciative.

I was reading a post here (XCode 8 generates broken NSManagedObject subclasses for iOS 10), and after reading the answer by Ryan H. I figured to give it a try.

By setting the codegen option to manual and setting the global space to my current project (see attached image), I deleted the files in the derived location and now they don't reappear and I don't get the duplicate error and everything compiles. I'm not sure how the codegen option even changed in the firstplace but something to watch out for sure.
Sample Image

Error when creating NSManaged Subclass in Xcode 8.2 beta

The issue here is that as of Xcode 8, new projects using Core Data and new Core Data data models are configured to use automatic code generation by default. That means you don’t have to explicitly generate code for your Core Data entities any more, Xcode will take care of that for you. If you leave automatic code generation on and also manaully generate Swift classes for your entities, you’ll see an error like this.

You can disable automatic code generation for an entity in the entity inspector, or you can remove the manually-generated code from your project. Either of the two should fix this.



Related Topics



Leave a reply



Submit