Accidently Deleted .m File in XCode 4 - How to Recover?

10,382

Solution 1

First, you should always make sure the option to create a Git repo is turned on when you create a new project in Xcode. Then you should commit often, like every time you add a feature or fix a bug (maybe more often than that is there is a lot of code being written). That way you can just discard you changes and get back anything you lose.

FOr now recovering the file depends on weather you told Xcode to move the file to the trash or not when deleting and weather or not you have emptied the trash since then. If it is in the project folder or trash just re-add the file if not you need to find a file recovery app and hope the file space hasn't been overwritten yet.

Solution 2

I learnt the hard way that XCode 4 deletes files instead of moving them to the trash! Disaster is just one click away.

Obviously Time Machine or version control will not help recover recent changes.

Type "undelete files on the mac" on a search engine. I managed to recover most of my data using such a piece of software.

Solution 3

If you did not empty the trash since you deleted the file move the file from the trash back into your project and re-add to the project if necessary.

In the future at least use the snapshot feature of Xcode.

Better still use the build-in Git version control.

Get a drive and use Time Machine, it protects against this kind of inadvertent deletion, it has saved me many times in a way my RAID drive won't.

Share:
10,382
Vad
Author by

Vad

Updated on August 30, 2022

Comments

  • Vad
    Vad over 1 year

    In XCode 4 when I was deleting some images I had .m selected as well and oops... it's gone. I has a lot of work done for today. How can I recover? Please help. I did not use Time Machine backup recently and did not back it up somehow else. I need that one copy badly. Anything to try?

  • Vad
    Vad over 12 years
    XCode completely removed file. Trash has no file with this name. What can I try now? If XCode builds the app, can I still find this file somewhere else?
  • Vad
    Vad over 12 years
    I found however .o file which is compiled from my code. How can I decompile it? Will it give me my .m?
  • zaph
    zaph over 12 years
    No it won't, the source code is not in the .o binary. Looks like you will have to re-code the lost file. Well, this s something most people go through on the way to understanding how important backups are. Apple supplies some great tools, Time Machine, Xcode snapshots and Git integration among others. PersonallyI use Time Machine, Git (local and remote), a RAID drive and periodic drive backups.
  • theMikeSwan
    theMikeSwan over 12 years
    You must have emptied the trash after the file was moved over then. Your only option is a file recovery app and hope the file is still hanging out on the disk (don't write any files to the drive in question or it may get overwritten). Xcode only removes references to files from the project and will move files to the trash if you ask it to. It will not delete the file all together. Have you checked the project folder? By default Xcode just removes references to the file so it may still be there.
  • Vad
    Vad over 12 years
    No. Trash was not emptied. Never was. XCode deletes files completely unless you specify to remove references.