How to remove reference of file Xcode?
Asked Answered
H

6

15

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?

Hannis answered 4/4, 2011 at 22:46 Comment(8)
Can you not see the refence anywhere? Checked every group?Durga
No, no other class references those files. It seems like somehow the project keeps track of all files that have been compiled at some point or another and stores the reference.Hannis
And I assume you've tried doing a clean?Durga
I just did, and it didn't work either.Hannis
What does a search for the old files yield? Try opening the project folder through a separate text editor and do a text search of the names of the old files.Durga
Nothing, I deleted the files manually. The problem came when I removed them from the project, no message popped up on regards to delete references only, delete, cancel, options that usually appears when you right click on a file and delete it. Today when I looked at the project folder in Finder I saw those files that I thought I had deleted a while back, so I went on and deleted them from my system, but the project still thinks they are there, and they are nowhere on my system.Hannis
Sorry, not a search for the old files, a search in the project files for the names of the old files. If Xcode is mentioning these files, references must be in some of the project files. If the reference is stored in clear text, you should be able to find it.Durga
That definitely works. Create the file again and delete through Xcode. -thanksHelmer
H
17

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.

Hannis answered 12/4, 2011 at 23:46 Comment(5)
Thanks! :) Hmmm.. But is there any other way?Dilation
Can you not find those files in the actual folder for your project?Hannis
@JohnK You don't need the actual file in Xcode. What you need is the file name and the path. You can find these in Xcode's Issue Navigator (click the exclamation-point-in-a-triangle "Caution" symbol in the Navigator pane) as part of the warning message. Use Finder, Xcode, TextEdit, or any application of your choice to copy an existing file or create a new file to that location with that file name. The warning that the file is missing should now go away. Back in Xcode, use File->Add Files to "Project_Name"... to add that file to your project, then select the file and delete it.Vogue
This is still a problem in Xcode 8.3.2. and this solution still works.After renaming a file I could not get rid of the reference in git and the file missing warning message. Duplicated the renamed file, renamed to the original name, added to Xcode and deleted it. Later I have found this: https://mcmap.net/q/143921/-missing-file-warnings-showing-up-after-upgrade-to-xcode-4, even better solution.Sartin
Thank you! Seems pretty hackish. Wish I could remove the reference after I've deleted the file but Xcode is a bit too temperamental and controlling for that.Vote
E
11

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
    
Elkeelkhound answered 4/2, 2015 at 2:4 Comment(1)
I removed subproject, cleaned project, closed xcode, opened xcode and reference still existed, had to run @Fjohn's script to remove referenceExhibitioner
F
4

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.

Flexure answered 28/5, 2013 at 21:23 Comment(0)
P
3

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.

Please answered 31/5, 2013 at 23:35 Comment(0)
P
3

Go to Project > Build Phases > Compile Resources and select referenced Class and hit "-" .this Will delete reference And now Build Again.

Playoff answered 25/12, 2019 at 6:51 Comment(0)
D
2

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!

Dilation answered 31/1, 2013 at 8:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.