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:
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.
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
Playing a Video File from a Server in Swift
Facebook Share Content Only Shares Url in iOS 9
How to Change Label Constraints During Runtime
How to Remove All Navigationbar Back Button Title
How to Get the Size of a Scaled Uiimage in Uiimageview
Xcode 8, iOS 10 - "Starting Webfilter Logging for Process"
To Convert Image to Cartoon in iOS
iOS 8.1 Simulator Localization Broken (Nslocalizedstring)
Xcode - Error Itms-90635 - Invalid MACh-O in Bundle - Submitting to App Store
Uiwindow Not Showing Over Content in iOS 13
How to Change the Uisearchbar Search Text Color
How to Add Constraint Between a View and the Top Layout Guide in a Xib File
How to Solve "Error Running Pod Install" in Flutter on MAC
iOS Tesseract Ocr Image Preperation
Cordova: Start Specific iOS Emulator Image
Warning: Attempt to Present Viewcontroller Whose View Is Not in the Window Hierarchy