A N
A N

Reputation: 33

Can I recover source code from app on test iPhone --Swift/Objective C

I have spent the last 4 days coding 20 hours a day to make my first self guided project ever for iOS. I had a working prototype and decided to tackle the layout for landscape mode. Long story short, in my fiddling I made mistakes that ruined portrait mode and so I (being a complete novice in Xcode and to programming) accidentally clicked discard all changes thinking it would reset me to my last save. It ended up wiping my whole file and dumping some of the old contents into the trash.

I could only find half my project in the trash so I was hoping I could recover the code from my test iPhone that has an older version of the program saved on it and just start again from there (with backups this time).

My iPhone is a physical version (not the Simulator)

The Button I Pressed

Upvotes: 0

Views: 403

Answers (2)

Gordonium
Gordonium

Reputation: 3487

Unfortunately it is likely that you are out of luck here. Normally you would commit the changes and then, if you don't want them, you can revert back (and forward) as you wish. If you had commited (or stashed/staged) then you would be ok.

But...

There is a small possibility that Finder can help you though. Read this answer and see if that helps.

Basically, quit Xcode, open the file that you were working in using TextEdit, go to File > Revert To > Browse All Versions and see if you can restore one that you previously used. Do this for each file and then reopen Xcode and keep your fingers crossed and pray to the code gods!

Upvotes: 1

matt
matt

Reputation: 534885

When you said Discard All Changes, you were warned that this would discard all changes. If you went ahead and did it anyway, you have only yourself to blame: you were warned! You are now back your previous commit. Nothing after that is recoverable.

The correct procedure would have been, not to discard your changes, but to commit them! Now the current state of things would have been saved, and you could then proceed to work your way backwards to a working state of things in a recoverable and systematic manner.

By the way, this is not an Xcode matter or a programming matter; it's a version control matter. It's very good that you are using git, but perhaps you should pause and read up on it before you continue using it.

Upvotes: 2

Related Questions