Accidentally deleted file in Xcode - xcode

I accidentally had one of my files selected in a project in Xcode and pushed delete and it was deleted. Anyone know how to recover it? It won't let me undo. Please help.

The file itself is not deleted, it is simply removed from the Project Navigator.
To add it back, go to
File -> Add files to "projectName"
and select the missing file, after having navigated to the project's folder if needed.
Or simply hit cmd+z

May be its too late but for someone else it might be good to know, that's why I am answering it.
Go to File >>> Add Files'Your Project Name' there will be a list of all files which have been removed from project, select and add them back.
Now these files are back in project, but they don't have any reference yet so xCode will give you error saying "Storyboard do not have any file of this name", now you have to add references, for this just right click on that missing files and add that file to project.
NOTE: If you have removed files directly to trash then restore from trash and repeat second step to add reference back in project.

This file should be in the trash folder, look in that folder or you can search via apple spotlight.

The following steps will allow you to recover (a) deleted file(s):
Click on the trash icon on the bottom right
Search for the file(s) and move it back into your project folder
In XCode, go to File, Add Files to ..., then select the file(s) you've just restored

There are some files that XCode deletes utterly without warning. These files are permanently deleted unless you have a backup.

Related

How can I change the location of files in xcode project?

I put some files on the same level of *.xcodeproj file carelessly. When I move these files into the right location in Finder, Xcode tells me that these files are missing. So I delete the group which contains these files whose names have been read (I realize it is a mistake). And I drag these files from Finder into the xcode to build a new group. But when I try to run the project, Xcode still can't find these code. How can I solve the problem?
When you see a file that is red (or in the wrong place), you can easily correct the location of these files by using the file inspector (which appears along the right side panel of your Xcode window).
It looks like this:
Clicking on the Folder icon next to the name will bring up an open panel from which you can choose the correct location of the file.
There is an easier way to re-organize files through the Xcode project. You can use Synx, it automatically fixes file paths, through the Xcode project groups.
You can check Github page for Synx
Synx
After intalling Synx just run the command below
synx path/to/my/project.xcodeproj
I found the answer.
3 things
1
removed the reference to the red files
then dragged them back into the project
relinked all my .m and .h files just incase
2
then removed the .app reference and dragged it back in to the project.
3
removed any duplicates or red files in the build phases
Fixed
Thanks everyone for your suggestions and help
From my point of view i would definitely avoid the virtual folders in the Xcode.The disadventage of this approach is whe nthe project gets bigger and bigger you can not find corresponding files in your filesystem easy.Even you click on "Show in finder" you need to look for the file among tens of files.
My approach is creating the folder in the finder and then dragging it to project.when i need to create a new file in this subfolder is will be added there anyhow.
Drag the new files from the finder to the Xcode project file structure.
Remove the old files.
I had a lot of class and find a good solution for solve this problem :)
1- Select a file that you want to change the location (Red)
2- Select "show the file inspector" from right side in Xcode
3- Select wrong path or unexpected path and copy like this screenshot
4- Close your project
5- Go to your root project and right click on "project *.xcodeproj" and select "Show package contents"
6- Right click on "project.pbxproj" and open with TextEdit
7- In the file select "Find and replace" or click on " Option+Command+F " and find location that you copied and replace with "" empty
8- Save and open the Xcode :)

Can't delete or rename files in Xcode 4.6 Project Navigator?

Something has become buggered with my project.
I can't delete files or rename files from Project Navigator view.
It may have something to do with source control? If I highlight 5 files in Project Navigator and hit delete and then move to trash the first file gets a source control "D" marking beside it but all of the files still remain.
Restarting mac/xcode has not resolved it. Any ideas?
Same thing happens to me for a while now.
Using git.
So far I'm able to work around this by deleting the files one at a time, which moves the file to trash but doesn't remove the reference. And then deleting the references again.
Similar problem with adding files to the project and renaming them.
For adding: first move/copy the required file in the project folder to the desired location, and then add from Xcode deselecting the "Copy items..." checkbox.
For renaming: find file in finder, rename IN FINDER, then change the name accordingly in Xcode (or choose the file again from the right panel).
Hopefully we won't have problems like these after moving to Xcode 5.

How to stop Xcode from thinking files are missing

I deleted some files from my project (a pair of .m/.h).
However now every time I build Xcode warns that the files are missing (though the build is otherwise successful).
I can't see where/how Xcode thinks the files are needed, it must have some reference to them somewhere but I can't find it - the files are not listed in either the compile sources section nor the copy bundle resources section. Where else might they be listed such that Xcode feels the need to warn about them not being physically present?
To delete them try this:
create a file named like the missing one
copy this file into your project folder, so that Xcode recognizes it
right click on the file inside Xcode in the project view
select delete
select move to trash, when Xcode asks
This worked for me for files, however I have the same problem with empty folders. If somebody knows a way to get rid of the missing warning for them, please comment.
If the files are missing from the project navigator or your checkout, but not included in the build for the current target, then the build might succeed despite the warnings.
XCode's Project Navigator keeps track of files, the directory they're in, and the state in git or svn. The project warnings when opening a project are shown in the status view at the top of the window. You can review these warnings when you press command-4.
The project navigator marks files that it tracks, but that it cannot find, in red in the folder view (press command-1 for that view). If you see red file names it might be that you deleted or moved them into another folder without XCode knowing about that. Then select the red filename and delete it.
On top of this the files might be "missing from your work copy", but still present in the repository. You can do two things in the terminal to sync with or delete the file from subversion.
svn up file
svn rm --force file

How do I remove a file reference in Xcode?

This is an odd one. I added a file to a project, thought I didn't need it so deleted, then realized I did indeed need it. When deleting I was prompted for whether to move to trash or just remove references, I chose remove reference. Now I can't add that file back in because I'm told there's already a file there by that name. What's going on here? There is no file by that name in the project listing. Is there some other place I need to go to remove something?
If you only removed the reference to the file, then it is still located in the project folder and you can't add a new file with the same name. So you should go to the folder where your project is located, and delete the file. (Right click on the project and select Show in Finder)

xcode: Why can't I copy a file into a group in xcode?

I renamed my root project folder and opened it up in xcode.
about 20+ files shows up in red (indicates missing). I then delete the "red" files and tried to re-add them back. but I get a copy error. "xcode cannot copy blah blah..."
1) How can I resolve this?
2) Is there a "Locate" feature that I dont know about?
---- RESOLVED ---
I didnt know that if there is a file with the same in physically in the project folder then xcode will not copy it to the project folder.
All i had to do is delete it from the project and then delete it from the file system. Or if the file you want is already in the project folder then you can re-add it back by not choosing the copy to folder option and also choose "relative to path" so next time you wont have this problem.
2) Is there a "Locate" feature that I dont know about?
"Get Info" on any file or group, first tab, there is a button at the very right where you can choose a new path. Works even for multiple selection (if they are in the same directory).

Resources