Duplicate files in Xcode manager? - ios

I've found that I get duplicate files in the Xcode manager. They appear to point the same file in finder. My first thought is that this was created when one of my colleges was, incorrectly, fixing a conflict in the source control. I'm not sure how to fix the problem. When I try simply deleting a duplicate Xcode crashes. I've filed this buy with apple. However I would like to remedy this problem in the meantime.
Thank You.

I don't see any duplicates in your list. Every class comes with a .h and a .m file (there are exceptions). Long story short, there's not a problem with the image you posted.

Select one of the CMPortfolio.h files and one of the CMPortfolio.m files (one of the references, rather) and press the delete key. When asked whether you want to remove the references or actually move the files to the Trash, choose Remove References. This should remove the duplicate references while not touching the actual files on disk (which allows the remaining reference to each file to be valid).

I had the same problem. That helped me: I moved all duplicated files in some other folder in Finder -> all files in project were red. Then I simply deleted the files from project, copied the files in the project folder and added them to project again.

Related

What does it mean when .xcodeproj files are shown in red in Xcode?

What does it mean when Library files are shown in red, as in the screenshot below? Does it mean these files have been added, but there's something missing from them?
This means that the reference to those two files has been lost. Someone moved or deleted them behind Xcode's back, and it no longer knows where they are.
As matt said earlier, this is because the project (notably the project.pbxproj file) has a reference to these files/subprojects, but they’re not found in the location in question. This can happen if you deleted them, renamed them, or you cloned some repo where someone forgot to add these to source control even though they’re supposed to be. It’s hard to say what happened without more information, but Xcode merely is telling you that files are not where the main project.pbxproj file is expecting them to be.
this happens when location mismatches or actual file is not there . search for these files in your mac , if is there , click on info and find the location . And if it differs , drag the file to app's necessary folder and in the pop up select copy

Xcode showing duplicate project

Never seen this before. Xcode is displaying duplicate project although only single exists on the disk. I have tried refreshing the status from Source control and also checked remote repository, only one exists there. When I refer both in Show in finder, both point to the same location. My worry is if the location is same, and I try to delete any of them, the project will be deleted.
Please rename the project and the associated files without Xcode going mental, and without having to manually re-import all files to the project.

.xcdatamodeld file not showing data model structure in Xcode

I have .xcdatamodeld file in my project but it not opening up into the data model.
When I click on the file in the left sidebar in Xcode, it continues to display the contents of the previously selected file instead of displaying the data model. Likewise, when I right click on the file and choose "Open As >", I cannot select to display it as a Data Model—nothing comes up. I checked out the code from the SVN repo and even the filer owner is not able to see it in his workspace.
This is a symptom that I have seen from time to time. In at least one case, this was due Xcode having the wrong path stored in the path component of the XCVersionGroup section of the project.pbxproj file, and having an apparently unnecessary additional name component in that section. It would probably be possible to manually edit this file, but I'm always reluctant to monkey around with the project file directly, and fortunately there's an easier way.
Navigate to your .xcdatamodeld file in the Finder. The easiest way to do this is Right click/Ctrl-click on the .xcdatamodeld file and select "Show in Finder".
Drag the file from the Finder and drop it immediately above or below the current reference to the .xcdatamodeld in the Project Navigator in your Xcode project.
Click OK to accept the import, ensuring that you are adding it to the correct targets. (Which targets are correct will depend on your project.)
You will now have two references to the same file in your Project Navigator. Clicking on either of them will now bring up the desired data model structure.
Remove the duplicate reference to the model file. Click on one of the file references (doesn't appear to matter which, though it may be better to remove the old one) and press Delete.
In the resulting confirmation dialog, be sure to select "Remove Reference" only, and do NOT move the file to the trash. (The two references point to only one actual file in the file system. Moving to trash would thus trash the only copy.)
You're now left with just one reference to the data model, and it works.
One thing that appears to trigger this bug is moving the .xcdatamodeld file in the file structure on disk. Even after correctly re-associating the file with the new location (i.e., it no longer appears in red in the sidebar), the one section of the Project file mentioned above is not correctly updated, and thus the file is not treated fully correctly as an Xcode Data Model file.
I encountered the same issue in Xcode 6.3
The only solution that worked for me was to move the .xcdatamodeld file out of my 'Resources' folder and into the project root folder in the Xcode project explorer (location on the filesystem doesn't matter)
I'm still not sure why, just moving the location of the file in the project structure causes it to not show up at all when clicked.. but apparently, at least in my setup, it doesn't like living in the Resources folder..
For some dark reasons, sometimes Xcode needs the xcdatamodeld fiel to be in the root folder.
I wrote an answer here that explain how to do this, but also a workaround to have this file where ever you would like to.
Cheers!
The .xcdatamodeld file is a package. It contains .xcdatamodel packages, one for each version of the model. Inside every .xcdatamodel there is a contents file, which is an XML with entities description. To see what is inside your packages, right-click them in Finder and choose Show Package Contents option.
Perhaps you didn't add the contents file into your repository. This way you will not be able to see your model when you create a brand new working copy from it.
I was victim of this problem today on Xcode8.
I solved it simply by placing the xcdatamodeld file outside any group in the Project navigator (left pane). As soon as I move it into a group, I can't open the little guy anymore.
I had a similar problem with Xcode 7.3.1.
It turned out to be related to the way the data model packages were configured.
I discovered that there was one embedded model package nested inside another. Let's say a top level data model called FolderNodes.xcdatamodeld containing another with exactly the same name ... FolderNodes.xcdatamodeld. Inside FolderNodes.xcdatamodeld is the actual contents file that has the model info.
The solution for me was to drag the embedded package FolderNodes.xcdatamodeld ( number 2) into the Xcode project and NOT its enclosing folder.
Apple uses the package for versioning but I think the logic associated with moving the data model file somehow breaks the original package creating a redundant wrapper.
Make sure your Version Editor is not active.
Having the Version Editor open results in the xml code to be displayed instead of the Data Model. You will also not be able to choose Data Model in the context menu of the xcdatamodeld file within the Project Navigator.
Happens on XCode 8.3 as well.
For me, moving the physical file to a different folder, then deleting the original reference, then adding it back to same place and establishing the reference again does the job.

Xcode 4.2 (Snow Leopard) Build Warning "Missing File"

I recently deleted a viewcontroller from my project (both .h and .m files) but know I get a 'missing file' warning every time I build.
Any ideas on this and is it something I need to worry about?
Appreciated
This is probably a version control issue if you are using svn or git. I had this problem and solved it using the solution provided in this post:
Missing file warnings showing up after upgrade to XCode 4
I recently faced the same scenario. Adding and deleting did not work for me.
However, I added them once more and right clicked on them. Under source control, I Discarded the changes and then deleted the files(Move to trash). This worked for me !!!
Ensure that it's not referenced anywhere in the project.
Look at the files on the bar on the left, make sure it's not there. Missing files are colored in red.
Ensure that none of your files #import the file.
Also, in the future, avoid storing files in parent directories. ../../ isn't something you want to use.
You likely have a 'dangling reference' in your target's list of files to compile or copy -- check your compile and copy phases for the target which emits the warning.
If it's been physically deleted, the simplest way is usually to enter the file name into the project navigator's search field - look for what Tom detailed - then delete the files from the project(s).
I had a similiar problem. I was trying to delete a .h and .m and I wanted to remove the files entirely, but kept getting errors if I chose "Move to Trash" instead of just "Remove Reference".
Turns out, I needed to just delete each file INDIVIDUALLY. Just add the files back in (if you have them somewhere) and re-delete them one at a time. Worked for me!

How to remove reference of file Xcode?

I had removed some files from my iOS project a while back and thought they had been completely deleted. After a long time I created another class which unfortunately had the same name as one of those that I had removed from my project (but the reference nor the file had been removed).
To make the long story short, my project tried using the reference to the old file, so I went through finder to delete the conflicting files. That solved the issue of which class was being reference. But the reference to the deleted files cause a warning in Xcode giving me a Missing File message.
Does anyone know how I can remove the old references in order to get rid of this warning?
Since the reference to those files needed to be removed, I tried creating the files again under the same name as those that I had removed manually and deleted them again through Xcode and selected remove references from the pop up.
After removing a subproject, the framework was always referenced in my code.
To remove this framework I had to do these steps:
remove subproject (reference)
clean project
close xcode
remove all derived and cached data with this script run in applescript tool :
tell application "Terminal"
do script "rm -frd ~/Library/Developer/Xcode/DerivedData/*"
do script "rm -frd ~/Library/Caches/com.apple.dt.Xcode/*"
end tell
In my case, adding and removing the external frameworks and using Clean did not solve the problem. Going to Target > Build Settings > Search paths and removing the offending paths from Framework Search Paths and Library Search Paths did the trick.
I hit the same issue today. Due to git merge issue, I ended up with a image file removed, but reference to it still exists. To clarify, My intention was to remove the image.
The simple way to fix this would be using vim, or other text editors
vim PATH_TO_PROJECT/{#projectName}.xcodeproj/project.pbxproj
and do a search on the name of the file you deleted and just delete all search results there.
Go to Project > Build Phases > Compile Resources and select referenced Class and hit "-" .this Will delete reference And now Build Again.
To be safe from this error, make sure you Remove Reference on the file first before making any changes (outside XCode) on that file like deleting in folder, renaming, etc..
To remove reference, in XCode, right click on the file then Delete. A pop-up will show asking if you want to move to trash or remove reference.
However, that popup won't show if you made any changes before doing Delete on XCode.
Just a tip!

Resources