Can I restore my Xcode source files back to a few hours ago? - xcode

I have used Xcode 7.something with Swift 2.2 or 2.3(even I cannot remember).
I upgraded my Xcode to version 8 and reformed the project to swift 3 syntax; which gave me a tremendous amount of errors.
I couldn't restore the project folder which was before the reform; just copied the converted file to somewhere else.
Then tried to convert back to 2.3 then I got even more errors... So I'm trying to find any way to restore the whole project file back to a few hours ago. Is there any way to get this successfully done? Thanks in advance!

If you used source control (git is the most common) and committed before and after then yes. (You should be using source control, and you should commit before doing something as sweeping as an upgrade from Swift 3.0)
If you have a backup then you can restore from a backup. (And you should be doing regular backups.)
If you haven't quit Xcode, and haven't closed the source files, you may be able to use multiple undo to back out the changes. (I suspect not on an automatic upgrade, but it's at least worth checking.)
If none of the above then you're probably out of luck and will need to work out the errors manually.
Swift 2 to Swift 3 is a big change, and there are going to be errors. It's painful, but a one-time thing.

Related

After upgrading Xcode 6, the snapshots are lost

I've lost the all snapshots I created, and the current project is somehow buggy and cannot function properly since I've tried to add some new features and failed.
Can anyone tell me how can I go back to my functioning version now that the snapshots are lost? Or can I retrieve one iTunesconnect version that i can edit?
Thank you very much!!!
Xcode 5 stored Snapshots in ~/Library/Application Support/Developer/Shared/Xcode. Xcode 6 stores them in ~/Library/Developer/Xcode/Snapshots.
You could:
Try moving them from the old location to the new location and see if Xcode 6 will recognize them
Open Xcode 5 and revert your project there (you can download it from the Dev Center if you deleted it during install, or it might still be in your trash)
The installer shouldn't delete the snapshot files.
Also, for the future, you should use Git or another source control software and not rely on snapshots for this.

Xcode creating tangled git repositories

I'm attempting to learn git and Objective C - yes, I know Swift is out there. I'm waiting for the excellent BigNerdRanch to publish a book on the topic. And since I have their other book I think it's good for me.
Anyway, I've been creating projects and checking the box for Xcode 5.1.1 to create git repositories on my Mac. For the last 2 projects what I find is that they are tangled up. What I mean is that when I go to the command line I see multiple Initial Commit's that were NOT done for that project.
If this is fixed in Xcode 6 - I can wait. Just curious why this is happening.
These are stored in Dropbox - could that be related? I'm about to reboot and shut down. Maybe somehow git is still open and pulling in everything?
Thanks!

XCode - Any way to recover code after "Discard Changes"?

I inadvertantly did a very stupid thing last night. I have been working on an iPad project for a couple of months and (even more stupidly) do not have a backup. By right-clicking on the project in XCODE, I mistakenly clicked "Discard Changes"
(stupidity reigns again) I did not have any commits since the initial and when I did the Discard Changes, it seems that it went all the way back to the initial commit, which if I am looking at things correctly looks like each file is as it was the very first time it was saved.
My question is: Is there a way to recover my work? Is it in the .git directory? Is a copy stored elsewhere? or as a last resort, any chance to recover some of the source text with an un-delete utility?
Thanks,
Bob
For little clarification.. one can put back files from the trash as discard changes sends the file in the trash
Answer copied from How to undo xcode discard all changes if not committed
Quit Xcode.
Open the file you wish to bring back your lost changes to using TextEdit.
Go to File -> Revert To -> Browse All Versions...
Scroll through the available versions. Hopefully you will have many available to choose from.
Select a version and hit Restore.
Follow 1-5 for all necessary files.
Launch Xcode. You should now see the M next to these files in Project Navigator indicating they include uncommited changes (the changes you previously discarded).
Completely new files you may have created and were discarded can be found in the Trash.
Also a small piece of advice. If you are in need to discard changes, prefer using Source Control -> Discard Changes by right clicking on files in the Project Navigator, instead of Discard All Changes which might give you all kinds of trouble.
Have a nice day. :)
Well luck was on my side after all. As it turns out, when I did the Source Control > Discard Changes operation, it did not make any changes to the source code save in my project directory. I was able to start a new project and added the files back in. Once I did that I was able to compile and run my project in the simulator just as it was before the incident. I now have a backup as well as committed the changes in git.
You have a hope of fetching this code if you "pushed" & committed your prior-to-discarded changes into your local git repository. Or if you're using MacOS's included Time Machine or some other automated backup solution.
Aside from that, you might be hosed.
If you're on Lion or later, you may have Time Machine backups even if you don't have an external drive. As of Lion, Time Machine will take 'local snapshots' of files; this is how they support the "Versions" feature that lets you go back to previous versions of your files.
If you didn't have Time Machine turned on, though... you may be out of luck.

Deleting Derived Data from Xcode 4.2 project doesn't re-index project

Indexing, code completion, & coloring disappear from my projects on a fairly regular basis, usually right after I add a file. And then it returns hours or days later, usually for unknown reasons (I've tried keeping a record but it's pretty random). CMD-clicking on even known terms (like viewDidLoad: or NSLocalizedString) result in a "Symbol Not Found" error.
It happens with Xcode 4.2 (I believe it happened in Xcode 4.0.2, but not as frequent).
I have no build errors, warnings, or static analysis messages.
I've restarted Xcode.
I've tried turning precompile off.
I don't have a case where I've got a circular header file include/import.
It happens if I use gcc, LLVM, CLang (in whatever combo).
It happens if I use iOS 4.3 or 5.0.
I've tried deleting the "derived data.", and even only the Index/ path.
After deletion & re-build I see the .hmap file & .xcindex folder (filled with db.xcodeindexdb* files).
...but I can't get code-completion, symbol detection, or coloring back.
What else can I do? I sincerely appreciate the help.
Have you tried a clean install (sudo /Developer/Library/uninstall-devtools)?
I have exactly the same problem for one particular project. Following workaround works for me: apart from deleting Derived Data , I make an SVN update or revert any file of the project. If the project file itself is changed my Xcode displays wrong target ,so I close the project and re-open it and then indexing starts properly.
The most reliable way I've found to force re-indexing of the project is to change the build settings, specifically 'Run Static Analyzer' - I wish I had a real answer though.
This might seem like a silly response, but have you tried to repair file permissions under disk maintenance?
Your thread is old, but anyway...
Deleting the derived data folder helps me everytime. I have to do it quite regularly, which is very annoying. Your find the path in the xCode-Settings(cmd+,) in the locations-tab.
I just had this issue. What worked for me is clearing the derived data, then closing the project and re-opening it. It didn't reindex until I closed and re-opened the project. The project never compiled fully, so it didn't even have to finish building to work.

Xcode 4.0 hangs on loading project due to the corrupted repositories?

I was trying to commit some changes, Xcode was hang on bringing up the changed files. So I killed (Force Quite) the Xcode. Then next time when trying to bring up my project, Xcode just hangs on loading project. Firstly I thought that maybe my project file was corrupted, but it still the same behavior with my backup project file. So I guess that the default repository for my project is corrupted.
The question is - where is the location of the default repository for my project? can I "remove" it to see if Xcode can starts up properly w/o it?
In XCode 4, you'll find the output contents for the project ~/Library/Developer/Xcode/DerivedData
I'm having this issue as well, intermittently with several projects. I suspect Lion resume as at least part of the culprit as I've had some success with deleting the content at:
~/Library/Saved\ Application\ State/com.apple.dt.Xcode.Lion.savedState
I'm presently reinstalling Xcode to see if that clears things up. A very Windows thing to have to do, eh?
[Sorry for hijacking such a dated thread.]
When we stumble upon this issue (it happens a lot lately) we usually remove ~/Library/Developer/Xcode/DerivedData/YOURPROJECT_RANDOMSTUFF and restart Xcode.
Usually the hang comes along with Xcode using all available RAM and causing the machine to swap heavily.

Resources