Xcode 5.1: any way to suppress Revert/"Keep Xcode Version" dialog - xcode

As of Xcode 5.1, when I change the project out from under Xcode (in my case, most commonly, by checking out another git commit), it throws up an annoying dialog, even when not active:
Worse, I'm using Spaces (or Mission Control... whatever the hell it's called now), and the dialog gets separated from Xcode and lost, and yet it's modal and keeps Xcode from accepting input. Sometimes I find it, or it pops up in the Xcode space. Sometimes this requires force-quit on Xcode to get control back.
Short of quitting Xcode every time I change commits, is there any way to end this madness?

I chose revert to disk because the "disk" is the new code which I just pulled down from my repo. "keep xcode" is the code that was sitting there before I chose to change branches or pull rebase.

Just close the project that you're going to make the change on before you make the change. I always close projects before I check out a different commit or branch, and never have this issue. It's safer to do it that way, too.
I don't think there's any way to just suppress it altogether, and if you did, you would have to choose a default behavior for it, which wouldn't necessarily always bet he same. So it would be a bad idea for Apple to give you an option of not showing it.

Related

I accidentally closed my Xcode application. How do I undo any changes?

I was testing out some new swift code. I knew that if I made any mistake I could simply revert back to my old code by pressing Command+Z.
But I accidentally closed my Xcode Editor while writing new code.
How would I undo the new changes and go back to my old original code? I did not make use of github for this.
There might be a chance you can view the file's old history. Check out George Marmaridis' answer
Here is what he says:
You might not be out of luck. Although Git can't help you, Finder may be able to come to the rescue!
If you have not turned off the Versions feature (which by default is turned on and you need a Terminal command to disable), then do the following:
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 2-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).

What happens when I "save" in Xcode IDE

I'm just starting to learn Swift using the Apple Xcode IDE. I made a little test iOS app and was trying various things when I inadvertently deleted my main code file (ViewController.swift). "No problem", I thought, as I had hit "Save" just a couple of minutes before. I exited out, then came back in, but it appeared to have autosaved.
I don't really care about this test file, but am wondering what is the proper way to save a project before trying something out (or before inadvertently pulling a bonehead move)?
What happens when I “save” in Xcode IDE?
When you hit "Save" the changes you've made are saved to disk. XCode doesn't do this automatically. If it crashes you may lose all your code written after the last time it was saved to disk. But XCode saves the changes to disk even without hitting "Save" button in some cases.
Xcode automatically saves changes to source, project, and workspace
files as you work. This feature requires no configuration, because
Xcode continuously tracks your changes and saves them in memory. Xcode
then writes these changes to disk whenever you:
Build and run your app
Commit files to a source code repository
Close the project
Quit Xcode
https://developer.apple.com/library/archive/documentation/ToolsLanguages/Conceptual/Xcode_Overview/UsingFileSaving.html
Use Git. If you don't know what it is, look into it. In the mean time, here is a tutorial or two.
To use it in Xcode, when you create a project, be sure to create a git repo:
Then be sure to commit frequently. Xcode has a built in Git GUI, so that makes it easier:
Then if you do anything that you shouldn't have you can either discard all changes (see the above screen shot, or if that can't help you, you can:
Open the 'Terminal' app
cd to the directory with the project
Run git log
Find the commit before you ruined everything
Copy the commit hash
Type q to exit the log
Run git reset --hard <THE-HASH-YOU-COPIED>
That should do it for you.
When creating a project check 'create git repository on my mac'.
Then commit changes when you're finished with one minor part and give the commit a comment so you know when looking into the history what changes you have done (quick overview).
With git you can quickly revert changes and go back to certain revisions like you can do in TimeMachine.
Further information are available at git's webpage.

Xcode 7.3 auto-updates IB files, clusters git

I have an Xcode project with, of course, nib files and storyboards. It seems like since I have upgraded to Xcode 7.3, the nibs and storyboards keep automatically updating themselves, thus marking them as modified by git.
This behavior used to happen only when opening the file: Xcode would then update some metadata. But now it seems to keep updating itself even if Xcode is not the active app. More specifically, I can be in Terminal, type > git status and have the expected result of > Your branch is up-to-date. Then, a few seconds later, run > git status again and have myStoryboard.storybardas a modified file. Xcode was never active during that period.
How can I avoid this behavior? Is it something new in Xcode 7.3?
Thank you in advance.
My guess is that this behind-the-scenes auto-modification is exactly to prevent the annoying feature where opening the storyboard file modifies it (and marks it as "dirty"). This way, the storyboard file is already modified (and saved) before you get around to opening it.
All of this has something to do with coordinating between the storyboard and your code, which is a long-standing problem that goes all the way back to the days when Xcode and Interface Builder were two completely separate applications that knew nothing of one another. Xcode today is a forced meld between these two applications, and tries to do all kinds of cute things behind the scenes so that they do know something about one another. What you're seeing is, I'm betting, a consequence of this.

How do I reverse something broken on an iOS / XCode project? How do I tell Xcode, "Try it again, for the first time!"?

I have been working with an iOS application in Xcode and, until about an hour ago, was steadily improving the software, and making Time Machine backups every hour or two. Then, as mentioned at What is causing this secondary damage? , I broke something and the problem was alleged in old boilerplate code.
I thought that I would use Time Machine to restore a "last known good" checkpoint, but Time Machine said I didn't have permissions. So I manually copied the past two or so known good backups, and Xcode claimed identical build errors, in the same two lines of boilerplate project code.
It seems to me that Xcode stores more state than in the project directory itself.
Is there a way to get Xcode to forget it knows the syntax errors, let go of that state completely, and process the code as of the last checkpoint or two where things have been working?
I'd appreciate knowing how to reset whatever state is finding those syntax errors in old and new versions of the project.
Two options:
Quick: Xcode top menu bar > Product > Clean
Thorough:
Close your project, but not Xcode.
Xcode top menu bar > Windows > Organizer > Projects
Select your project in the left navigation bar.
Once selected, there should be a "Delete..." button on the far right, for "Derived Data" -- press it.
Re-open your project, let it index stuff, and try building again.
Also, I strongly recommend learning/using Source Control. Xcode has it built-in now!

Make Xcode 4 stop auto staging with git

I hate it that whenever I make a change in Xcode 4 it automatically does a "Git add" command. Is there a way to make this stop?
What I do is perform all my git interaction through the command line. Since I can't get Xcode to ignore the fact that my project is under git control, and since therefore I can't get Xcode to stop doing git add for every new file I create, when I get to the command line the first thing I do is git reset to reset the index. This undoes all the annoying git add stuff that Xcode did automatically. Now I'm in charge of what goes into the index and so I get to form my own commits the way I want.
For Xcode 6 this is not an issue anymore. Visit Preferences -> Source Control tab and turn off 'Add and remove files automatically' checkbox
No. Xcode 4's git integration is "broken" in that they tried to present a uniform interface to source control regardless of whether the back-end is git or svn. That means they're supporting only the lowest common denominator of functionality. As a result, use of the index (the "staging area") is out. It always does auto-adds no matter whether you want it to or not.
EDIT: Actually, I don't think it auto-adds. I think it always does commit -a. Looking at git status on the command line shows me many new and modified files that are NOT staged. But I'm sure if I committed with Xcode they'd all end up in that commit.
For me, the solution was this one https://stackoverflow.com/a/6378745/1078859
TL;DR; remove the repository from xcode's organizer
While the question title says XCode 4 this question appears at the top for many search results related to this issue even in newer versions of XCode. Here is an answer that addresses newer versions of XCode. In XCode 6 you can turn off version control by going to XCode --> Preferences --> Source Control Tab and uncheck Enable Source Control.

Resources