36

I am running Xcode 4.3.3 on the new Macbook Retina and out of the blues Xcode started freezing right after launching. I was in the middle of working on two projects so when Xcode starts up it immediately launches the two projects I was working on. The first one loads sometimes but the second one always freezes. Because the project launches right away I cannot access any of Xcode's features. I can't even figure out how to stop the project from launching on start up. Here is what I have done thus far:

  1. Rebooted comp - still launches projects and freezes
  2. Deleted everything in cache ~/Library/Developer/Xcode/DerivedData - still launches projects and freezes
  3. Uninstalled Xcode (hold click in Launchpad, click the (x)). Reinstalled Xcode. - Still launches the projects and freezes
  4. Moved my projects from original folder - Still launches the projects and freezes
  5. Created a new iOS user2 and launched Xcode - does NOT launch projects OR freeze yay!
  6. In user1 copied freezing project to external, logged in as user2, launched project - Does NOT freeze! But now I need to transfer my Xcode profile and certificates to the new user.

So what the heck is going on? I would prefer to use User1 and would like to actually solve the problem so that I don't need to make a new user if it happens again. (User n+1, indefinitely is not an attractive option).

Xcode freezing on startup

BenHedges
  • 393
  • 1
  • 3
  • 7
  • Are you running any anti-virus software? I use Kaspersky and it does this to me. I have to stop the A/V while using Xcode. – Martin Jun 28 '12 at 14:39
  • 1
    if you dont get help here you should be eligible for apple support since its so new. also how did you reinstall? reason i ask is because all new versions of xcode are distributed from the app store so make sure you are getting it from there. I would also say to maybe check for updates both in the appstore and in xcode (xcode>prefrences>downloads) – owen gerig Jun 28 '12 at 14:40
  • I'm not running an antivirus and I installed right from the app store. I downloaded and reinstalled straight from the app store. jhabbot's answer helped me actually open Xcode and check for updates, but no updates. I can use Xcode again but my project still freezes. – BenHedges Jun 28 '12 at 23:47
  • http://stackoverflow.com/a/9936904/836407 worked for me. – chown Nov 15 '12 at 15:43

17 Answers17

45

Check out this: (quoted from here)

Restore sanity by not restoring

Thanks to Lion's Restore feature, all the windows you left open in a given application remain open when you relaunch it. That's awesomely helpful in a Web browser or a text editor. In certain apps, however—particularly those where you rarely need to revisit the same documents—the feature is more of an annoyance. Window resuming is actually configured on an app-by-app basis. Here are the Terminal commands to disable Resume in Preview and QuickTime Player X:

defaults write com.apple.Preview NSQuitAlwaysKeepsWindows -bool false

defaults write com.apple.QuickTimePlayerX NSQuitAlwaysKeepsWindows -bool false

Quit the apps before you try the commands. Again, swap "true" for "false" to reverse your change.

You may be able to do something similar for Xcode.

Otherwise, you can quit an application in Lion and discard the previously open windows by holding the option key while pressing CMD+Q. So you could try starting Xcode and quitting it with option held before it's had a chance to open your windows, then re-launch it and it shouldn't try to open the windows. Then you can try to fix the problem.

Update: Here is some additional information from comments that solved the problem...

Now to try and fix the project... Remove the following directories:

MyProject.xcodeproj/xcuserdata
MyProject.xcodeproj/project.xcworkspace/xcuserdata

Those directories store things like window positions, what files are open, which project groups are expanded, etc. so one cause could be if you use source control across multiple machines that have the same username and those files aren't ignored (which they should be if you're using source control). Retina vs. non-retina or different versions of Xcode could use those files differently and the source-control merging could make them inconsistent. So make sure you remove and ignore these directories in source control so that they don't get re-added and cause the problem again.

jhabbott
  • 18,461
  • 9
  • 58
  • 95
  • 2
    Thanks the option then CMD+Q (plus some very nimble fingers racing against the SSD) worked. It took a couple tries and I still needed to force quite Xcode but on my fourth attempt Xcode launched without launching the projects. Thanks! The only problem now is that the offending project still freezes. Any thoughts on how to fix the project? I can launch the project just fine when I copied it to a new user. – BenHedges Jun 28 '12 at 23:51
  • 3
    Glad it helped - now to try and fix the project... have you tried removing the `MyProject.xcodeproj/xcuserdata` and `MyProject.xcodeproj/project.xcworkspace/xcuserdata` directories? From step 6 in your question it suggests this may be the problem. – jhabbott Jun 29 '12 at 00:06
  • w00t it worked, thanks. In terminal I navigated to my project and deleted xcuserdata and xcworkspace with $ rm -r xcuserdata and $ rm -r project.xcworkspace After which the project was no longer froze. As another note after working on the project for a couple hours the project froze again and I had to repeat the process. I'm not sure if this is an issue with the latest version of Xcode and the Macbook retina but I didn't have the problem on my old macbook. – BenHedges Jun 30 '12 at 22:24
  • Those directories store things like window positions, what files are open, which project groups are expanded, etc. so one cause could be if you use source control across multiple machines that have the same username and those files aren't ignored (which they should be if you're using source control). Retina vs. non-retina or different versions of Xcode could use those files differently and the source-control merging could make them inconsistent. But if that's not the case then it sounds like a bug, yeah. – jhabbott Jun 30 '12 at 23:18
  • 1
    option CMD+Q did not work for me, but rm -R those 2 directories did. – bulltorious Mar 04 '14 at 14:49
  • Awesome. Though not the same issue, I had a similar issue with XCode hanging when trying to open any file with XCode 6.3 Beta 4. I removed those project settings and it's working again. Thanks! – Darren Cheng Mar 30 '15 at 23:39
  • In my project, it was specifically the `UserInterfaceState.xcuserstate` file inside of `xcuserdata` that I needed to get rid of in order for Xcode (11b5) to stop trying to open the file that was causing it to hang. `xcuserdata` also seems to store things like your list of breakpoints, which you may find useful to preserve. – Ronald Martin Aug 11 '19 at 06:05
  • Force quit xcode, then open it and immediately click `Option`+`CMD`+`Q` before it attempts to loads all windows and gets stuck. This will make xcode exit without saving all windows, and the next time you open it - it opens fresh. No need to delete any data manually. – Lorraine R. Dec 02 '20 at 22:16
33

What fixed this for me was removing unsaved document in ~/Library/Autosave Information. After Xcode launched without any problem.

Montas
  • 674
  • 6
  • 13
26

Using answer in apple.stackexchange.com did the trick for me:

Removing the ~/Library/Saved Application State/com.apple.dt.Xcode.savedState/ directory might help.

If this did not work, then remove ~/Library/Developer (brought from here and here)

VSB
  • 9,825
  • 16
  • 72
  • 145
14

Its silly but after trying all solutions I found the apple icloud was trying to backup my repos from my documents to the cloud and run it from there causing very slow load times and freezes - make sure your repos are located outside of icloud folders or just disable it.

Ross
  • 141
  • 1
  • 3
11

Open your project and then right click on yourprojectname.xcodeproj then click on Show package contents.

There you're going to see the xcuserdata. Delete it.

Next, right click in project.xcworkspace, click on Show package contents and delete the xcurserdata.

At the end, restart your Mac and re open your project, everything should be fine again.

Ziad Akiki
  • 2,601
  • 2
  • 26
  • 41
JasonSa
  • 111
  • 1
  • 2
7

I accidentally double-clicked on Projects folder in Xcode Open project dialog, it tried to open all projects at once, and freezed. Advices from this branch did't help, but after some searching i found the files, that should be deleted. Locate current_user/Libraries/Autosave Information and delete all Xcode-related from there, that should help.

6

I tried everything and nothing helped. Lost already 3 hours while trying to solve this issue.

What helped and solved everything was to run this in my terminal

defaults delete com.apple.dt.Xcode
Tornike Gomareli
  • 1,564
  • 2
  • 16
  • 28
5

A problem which I had: When I added a casetagram library into my project, then a few seconds after launch of Xcode, before indexing of files (as I think), it had become freezes. After simply rename folder on other name and rename it back - Xcode freezes again.

My solution:

  1. Command-Option-Shift-K to clean out the build folder.
  2. quit Xcode and clean out ~/Library/Developer/Xcode/DerivedData manually

Then:

If you have some time before Xcode will be frozen: You must launch Xcode, then quickly open Organizer->Projects and remove your project from list (project, on which Xcode freezes).

If you haven't enough time for open of organiser then: 1) quit from Xcode. 2) rename folder where your project is located. Then perform the 1 variant of solution (open organizer and remove project on which Xcode will be frozen) 3) rename your folder back

If Xcode will frozen after all of this actions, try to open other project and compile it. If it works, go back and try build your project on which Xcode was frozen. If Xcode again will be frozen then reason of it at this concrete project

iVader
  • 212
  • 2
  • 4
4

I experienced the same problem today, with the same configuration of Xcode 4.3.3 running on a retina display MacBook Pro. I read through this page, and decided to first try deleting the files listed above by jhabbott: MyProject.xcodeproj/xcuserdata and MyProject.xcodeproj/project.xcworkspace/xcuserdata directories. That worked. After deleting the files I was able to start Xcode and then open my project by selecting File > Open Recent. You can delete those items directly from Finder if you hold down the command key and click on the project file, and then from the menu choose Show Package Contents.

coder
  • 41
  • 1
  • Many different things can cause Xcode to freeze on startup. It’s worth investigating all of them. Deleting the xcuserdata directory definitely helped me. – codecaffeine Jun 04 '13 at 14:17
4

To open Xcode without it automatically loading the last project, hold Shift-option while picking the icon from the dock. This helped me bypass the 'bad project' and troubleshoot from the IDE.

samonthego
  • 41
  • 3
3

I fixed this condition by renaming the root directory that contains all the Xcode projects.

While Xcode is not running, rename the directory, then start Xcode. Xcode won't be able to find the projects and will silently ignore them. Quit Xcode, revert the directory back to the original name, and start Xcode again. It should not try to load the projects at startup.

Not sure why this works but your step #4 (moving the projects) does not.

Ian
  • 111
  • 1
  • 3
  • Renaming the root did work to stop the projects from launching, thanks. I'm perplexed as to why moving the project didn't work. Thanks its another option along with Opt+CMD+Q. Now how can I troubleshoot the freezing project? – BenHedges Jun 28 '12 at 23:57
  • I think The reason moving projects doesn't work is that the filesystem is too clever and files are referenced by inode instead of absolute path - this means when the file moves somewhere else references to it don't break. Good for some things, bad for others. – jhabbott Jun 29 '12 at 00:00
3

If anyone is still having this issue, if your project is in iCloud drive, this can cause an issue with the syncing. By moving it outside of the drive, it fixes the problem. (For me at least, I tried everything else)

ZachtheBoB
  • 398
  • 3
  • 10
  • 1
    OMG yesssss, I tried everything + installing another XCode version, at the end, when I saw your answer, tried to clone the project to my downloads folder rather than my iCloud drive, and it worked instantly ! Thank you – Hussein May 01 '23 at 12:34
  • This is a duplicate of https://stackoverflow.com/a/58855653/1693173 – progrmr May 17 '23 at 18:24
  • I fixed it with this, but I wonder if this would work: `killall -9 bird`. This kills the icloud sync process. Somebody try it! – user3413723 Aug 20 '23 at 09:14
1

For me the issue was actually iCloud Drive syncing files at the same time Xcode was trying to access them.

I was able to fix the issue by copying the project to a directory that was not synced by iCloud Drive (using cp command, not Finder)

Charlton Provatas
  • 2,184
  • 25
  • 18
0

It happened to me after restarting the Mac. Maybe something not saved properly and after power up Xcode remained "not responding". I renamed the root of the last project I opened. When opened Xcode instead of being stack it opened and response with error that it couldn't find the project. Then I jsust opened the project regularly and it worked fine.

Zohar Chiprut
  • 752
  • 1
  • 8
  • 18
0

Nothing worked for me until I realised my project file was synced to iCloud. This was causing some files to not be on my local machine and preventing Xcode from starting.

If none of the above solutions work, then try adding ".nosync" to the end of your workspace folder name. Wait a few minutes until the cloud icon disappears, indicating that all files are on your device. Then Xcode should work perfectly.

Ralek
  • 1
  • 4
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Vikram Parimi Sep 16 '22 at 12:30
0

The problem could be due to a bad internet connection: probably Xcode when opening the project, is waiting to receive or trying to send, information that does not arrive. Try launching your project after temporarily disabling Wi-Fi on your Mac. Or switching networks to one you know is more stable.

Cue
  • 2,952
  • 3
  • 33
  • 54
-1

You just need to remove these directories:

MyProject.xcodeproj/xcuserdata
MyProject.xcodeproj/project.xcworkspace/xcuserdata

As jhabbott says, these directories store the locations of open files, windows, etc. and can be safely deleted. Generally the issue is that you have a reference in the xcuserdata to an old network share that doesn't exist any more, and xcode sits there for a long time trying to access it.

Make sure you delete these directories for all your XCode projects.

CpnCrunch
  • 4,831
  • 1
  • 33
  • 31