Xcode disable recompiling every time I Git Checkout - xcode

I work on a large Xcode iOS project that takes about 20 minutes to fully compile from a clean state. I've disabled compiler optimization in the debug mode as well as dYSM so I believe this is the fastest that this is ever going to compile. Every time I git checkout another branch, even simple one file changes, Xcode has to recompile everything and it takes forever and slows me down. Is there anything I can do to disable that? Thanks!

What I've observed about git checkout is that it resets the file-created / -modified date of the file to now. I think Xcode sees that this has changed and takes it as a signal that the file has changed behind its back.

Related

Xcode 9.2 is re-indexing from scratch each time I open it, even if nothing changed

I have a project (big project), that takes about 30 minutes to be indexed by Xcode. Xcode consumes 100% of my CPU for 30mn.
OK why not, that sounds a bit rude to use 100% of the CPU for a background task, but why not.
Now, if after 30 minutes, I quit Xcode, and re-open it, without touching a single file of my project, it starts again to index for 30 minutes.
Is this the intended behaviour? Is there a way to fix it? I don't want to turn off inedxing, I tried it, and code completion is HS.
Try adding this flag to your build settings.
Xfrontend -warn-long-expression-type-checking=400
It will cause warning where the compiler take a long time to deduce a complex expression.
This may cause a build error which will go away after you find the slow expressions and then remove the build flag.

Xcode always builds all my targets in the current scheme, even without any change

With Xcode 8.1 I see this phenomenon that even if I didn't change something on triggering Run Xcode goes through all targets of the selected schema and builds them (which is a mix of mostly C++ and some Obj-C code). All images are processed, all scripts run etc.
However, in the build log I see that the cpp files are not really compiled, they are just listed, so the overall build time is not that of a real build. Still, even with a few seconds on each target I get a delay of 10+ seconds (and a lot of file operations) before the debug session starts actually, which is a pain if you need to restart the debugging session frequently.
Is there any solution to avoid this "pseudo build"?

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.

Xcode 4.3.2 and 100% CPU constantly in the idle time

My Xcode started to behave very heavily from yesterday when working on medium size project (around 200 source files). Project compiles correctly and runs in both simulator and device. I do not use any 3rd party libraries, except few widely used includes (like JSON or facebook ios sdk).
It constantly uses CPU(s) at full speed, even if it is in idle state (no indexing, no compiling, no editing). The usage of RAM is relatively normal (300-50MB).
My machine uses: Core 2 Duo 3.04Ghz CPU, 8GB of RAM and Vertex OCZ 3 SSD drive.
I have tried every suggested solution found at stackoverflow:
Cleaned project
Cleaned Derived Data in Organizer
Cleaned repositories in Organizer
Cleaned xcodeproject bundle from workspace and userdata files as suggested here: https://stackoverflow.com/a/8165886/229229 (it is helping just for a moment and starts again after minute or so).
Restarted Xcode many times (with the same effect as in 4).
Disabled "Live issues"
even Reinstalled Xcode
Nothing helps. In most cases, Xcode indexes the project for a moment, then comes back to the normal performance, but after a while becomes unusable again. CPU jumps back to 95-100% for both cores, intelligence hangs, etc...
I am attaching screenshots of how the Xcode processes are seen by the Instruments:
UPDATE:
After a moment of hope that I solved the problem by moving around few
#import "header.h"
statements from headers to the implementation files and exchanging them with forward declarations ... the problem came back again after a while.
I am adding the console log.
The strange thing is that the logs related to Xcode show up after I quit it, not during the run itsef.
Console logs:
5/11/12 9:27:03.777 AM [0x0-0x45045].com.apple.dt.Xcode: com.apple.dt.instruments.backgroundinstruments: Already loaded
5/11/12 9:27:05.571 AM Xcode: Performance: Please update this scripting addition to supply a value for ThreadSafe for each event handler: "/Library/ScriptingAdditions/SIMBL.osax"
5/11/12 9:27:58.168 AM Xcode: ERROR: Failed to create an alert for ID "enabled" based on defaults: 1
What stopped my nightmare was:
Change Always Search User Path to NO in Project build settings (bolded).
Remove -objC flag Other Linker Flags (also bolded setting).
And then delete Derived Data and wait until Xcode reindexes.
I am not sure which of them helped bacause I changed both of them at the same time and I am so behind my schedule I have no time to test it. I will improve this answer when I reproduce the bug and solution in spare time.
However, there is a hint:
*Rethink and recheck your project / targets build settings.*
It is highly probable that this strange behavior may be caused by some unfortunate combination of build settings.
All my projects does this from time to time. I can shut down X-code and start it up again and it'll run fine for a while, then go back to using 200% CPU time (two cores fully loaded).
My solution is to use AppCode as my primary IDE (has the added benefit of being a much better IDE, but that's another story). I only start XCode when I need to edit storyboards and shut it down when I'm done - usually that keeps the problem at bay.
AppCode runs off the same project files/structure has better and faster indexing and never runs into this issue, so I can't see how this can be a settings/configuration problem - it must be a bug in XCode. Hence, I would not waste time changing your code structure as it will most likely only delay the problem, not fix it.
No way to know if the OP actually had a different root cause, but for me it appears to have been an Xcode glitch with git. Adding / committing my current changes solved my problem. Here is the complete scenario and what I did to get it fixed:
Environment:
Xcode Version 5.1.1 (5B1008)
Macbook Pro OS X 10.9.2
2 GHz Intel Core i7, 8GB RAM
I noticed Xcode was starting to eat 200% of my CPU constantly.
Not sure exactly when it started, but Xcode did freeze up on trying to make a snapshot (400% CPU usage for several minutes until I force-quitted Xcode)
After reopening, I noticed Xcode was still stuck indefinitely at 200% CPU usage.
Closing all projects did not work.
Deleting all derived data and restarting did not work.
Uninstalling Xcode and reinstalling at first held promise, but once I re-opened my main project, the CPU returned to a constant 200% CPU usage. (after indexing finished)
Closing the troubled project did not help. Xcode was now stuck again in forever-kill-200%-of-CPU land.
After looking around Stack Overflow, multiple people alluded to git being an issue.
I have a slightly complicated git repo (has a submodule repo and a subproject within the main Xcode project).
I had pending changes in both the main repo and submodule portion of the repo.
I closed Xcode and git added & committed all my current changes.
Reopen Xcode and VIOLA! No more CPU being killed. Back down to 0.0% idle usage.
Xcode 5.1.x seems to struggle with git in other ways for me too (sometimes does not pick up changes in the GUI, etc.) so perhaps there are Xcode git integration bugs.
It looks like it's spending its time parsing ObjC included in the PCH.
How many PCHs must clang generate? In your project, that would be one for C, one for ObjC, one for C++, one for ObjC++ for each dialect/lang used in your project and any dependent targets. That is -- if you have a dependent library included in your app's PCH and you are hacking on that library, all code sense in the app target must be invalidated and parsed again each time you alter a header included by your pch. And if your target compiles a C file, it will need a PCH for C. If it needs one for ObjC, it will need to generate one for ObjC.
How often do you alter the PCH (or anything included by it)?
Remove includes from the PCH. It's not unusual to see every linked framework included in a PCH (avoid doing this!).
If you change your build or preprocessor settings, it may need to rebuild the code sense index for the target(s) entirely each time.
Have you tried disabling live issues?
On my projects (all of them) it was the autocompletion/intellisense. When I changed one line of code in my .h files, it went haywire, +100% CPU usage (more than one core).
I just disabled it, now I have to think a bit more for myself (like I used to do on windows) and it works great at low CPU usage.
i used to encounter this problem.it is caused by git.Although i don't know the git very well.i removed the file named .git in the project directory and it turned to normal.by the way,the .git is hidden.

When and why should I clean the build in XCode

Every once in awhile, the solution to an aggravating problem in XCode is to hit Product → Clean, and this seems to clear some cache and problems disappear.
But what is it actually doing? And more importantly, WHEN should I be doing this? It seems to be necessary more often when dealing with Core Data, but I haven't really been tracking it.
As a side question, WHY is this necessary? XCode seems to do a lot of stuff in the background (autosave, autocompile, etc). Why doesn't this also just happen in the background?
It's because there are a lot difference when you are working with a very very big project with a lot of files and objects. Imagine that you need an hour to recompile a entire project, so you will think before do this. But in our world, this is a fast task.
XCode use the make program. So, it compile only what was changed.
I can list same cases you need do this:
Always you will create a App for App Store. This safety thing to do.
Always you use the XCode Snapshot. I have bad time when I restore a project and build the app. XCode used old compiled files and a lot of time was lost to search it.
Maybe when you restore a old code with git. Is the same idea of the Snapshot
When you delete or rename a file in project. It don't delete the compiled file, so the program can work, but if you recompile, will see the errors.
When you see that sometime the build have a strange behavior. Or only to have certain that XCode use only your newer files.
I don't remember exactly but i have seen the build use old #defines. Rebuilding can make you more safe about your program. But don't need do this all time.
I am almost certain that XCode loses track of things and sometimes it doesn't recompile (or link, not sure) everything is needed. I have to resort to clean and build all most often than it should. Maybe it's just me, but I doubt it... XCode is the IDE with most bugs I have worked with

Resources