88

So, I opened a xib file from an older project and it caused a crash. That's not the issue. The issue is that now when I restart Xcode, it tries to open all previously opened projects (and files) and the crash re-occurs. Where does Xcode store the list of previously open files, and how can I get it to start 'clean' without any open projects?

Update: As a note - this is the latest version of Xcode 4.2 on Lion.

3
  • 1
    As an addition to the answers, if you want to reset project state, you should remove directories: YourProjectName.xcodeproj/project.xcworkspace/xcuserdata and YourProjectName.xcodeproj/xcuserdata
    – Borzh
    Commented Oct 21, 2018 at 23:44
  • 1
    @Borzh your comment really helped me. Thanks
    – Andrew
    Commented Jun 12, 2020 at 19:23
  • 1
    a comment for my future self, deleting the project and restoring it from the trash can worked for me Commented Aug 2, 2021 at 13:52

9 Answers 9

162

Press option+Shift when clicking on the Xcode icon in the dock. Xcode then starts without opening previously used projects. This is related to version Version 4.5.2 (4G2008a) but I am almost sure that I used it in older versions as well.

5
  • 4
    side note... don't do that in the Applications folder as it will highlight all the way from where you had selected (probably A...) and open all of them. Every application in my applications folder is now launching Commented Jan 26, 2013 at 21:01
  • 1
    To reiterate, I had to pin Xcode to dock to get this to work. Launch it from Finder with this shortcut just causes it to load with slow animations. Commented Sep 28, 2016 at 10:10
  • For some reason, my XCode crashed everytime it tried to open some previously closed projects. This solution really saved my day. Commented Mar 27, 2017 at 15:58
  • That's the option I was looking for: Opening without trying to open previous project (which was creating the issue). I could delete my account and redo it.
    – Larme
    Commented Jun 9, 2020 at 6:16
  • Did not seem to work under 15.1 Commented Jan 14 at 18:50
37

I've recently had a similar problem. I tried the methods above and could launch Xcode from the command line, but as soon as I tried to open from the finder, it would try to open the "bad" document and hang.

I eventually resolved it by removing the contents of :

~/Library/Autosave Information/
~/Library/Saved Application State/com.apple.dt.Xcode.savedState

This seems to have fixed it for me.

1
  • 1
    FWIW, deleting the second directory listed alone worked for me
    – mjohnsey
    Commented Mar 17, 2022 at 3:38
31

I just spent half the day stressing over a very similar issue. I had tried updating and reinstalling Xcode - but the problem still persisted. Thankfully, a few minutes ago, I managed to solve this by doing what your question states with the help of this post.

Basically, I opened another Xcode project (it can be any file, though) from the terminal using the following command:

open -a /Applications/Xcode.app app.xcodeproj/ --args -ApplePersistenceIgnoreState YES

This successfully launched Xcode with the standard 'Welcome to Xcode' dialog box you usually get. Hope that helps!

1
  • 3
    I used simpler open -a /Applications/Xcode5-DP2.app/ --args -ApplePersistenceIgnoreState YES
    – Conor
    Commented Jul 25, 2013 at 10:03
18

You can stop Xcode from opening the last project by running the following command:

defaults write com.apple.dt.Xcode ApplePersistenceIgnoreState -bool YES

This and other useful commands are here.

2
  • 4
    Saved my day! Stuck on large project loading.
    – AlKozin
    Commented Sep 27, 2022 at 5:42
  • 1
    The true answer!
    – markturnip
    Commented Apr 27, 2023 at 5:53
12

I was able to do it with the following command line in Mavericks:

open -a /Applications/Xcode.app --args -ApplePersistenceIgnoreState YES
10

Not specific to Xcode:

Please make sure Close windows when quitting an application checkbox is checked under System Preferences > General.

5
  • 2
    Yes this is true - but this does not address the problem in the question. The question deals with the situation when Xcode crashes because of a problem in a file - and then will continue to try and launch that file on restart.
    – dtuckernet
    Commented Sep 17, 2013 at 11:41
  • 1
    Yes, it does. Problem is not related to Xcode, or crashing. Re-opening last open windows is a macOS feature, and it is causing the problem OP experiencing. Commented Jul 20, 2019 at 5:39
  • It doesn't. I always had that checked but experience the same problem as op. Commented Jun 24, 2021 at 15:30
  • Wow. In 2022, this box is mysteriously checked again. Still a valid answer for the opposite solution.
    – David
    Commented Apr 2, 2022 at 16:07
  • This doesn't help when you can't complete the close due to hang or crash that happens before it.
    – Bobjt
    Commented Nov 30, 2022 at 19:50
1

Instead of looking for the file that contains Xcode's settings, take a look at the settings themselves using the defaults command:

% defaults read com.apple.xcode | more

I notice two keys that might be relevant: NSRecentXCFileDocuments and NSRecentXCProjectDocuments. Both appear to be arrays, so you could reset one like this:

% defaults write com.apple.xcode NSRecentXCFileDocuments -array ""

Alternately, you could use the defaults read command to dump the settings into a text file, edit that, and then use defaults write to update the settings:

% defaults read com.apple.xcode > xcsettings.plist
// edit xcsettins.plist with your favorite editor
% defaults write com.apple.xcode < xcsettings.plist
4
  • I dropped both of those settings values as well as another setting which contained references to the open files and the projects and files are still opening on launch.
    – dtuckernet
    Commented Nov 8, 2011 at 16:51
  • 2
    @dtuckernet A simpler approach, then: move or delete the file that's causing a problem on launch. If I understand you correctly, the issue is just that Xcode tries to open the file every time it launches, and that causes a crash? Moving the file should end that cycle.
    – Caleb
    Commented Nov 8, 2011 at 16:55
  • This is old information and no longer applies to modern Xcode.
    – user246672
    Commented Nov 1, 2013 at 0:11
  • 1
    @Barry It's an old question. If you read questions that are 2 or more years old you're going to find a lot of information that's out of date.
    – Caleb
    Commented Nov 1, 2013 at 4:24
1

Given the project name "MyProject" in directory ~/Documents/Projects/MyProject do the following:

  1. cd ~/Documents/Projects
  2. mv MyProject MyProject.x
  3. open -a Xcode
  4. close MyProject (Option+Command+W)
  5. mv MyProject.x MyProject
  6. open -a Xcode

The this solved the crash for me... however my Storboard was corrupt. Fortunately the Time Machine backup of the folder was intact, I just restored it.

1

For me it wasn't a project that was causing the crash on startup, it was a particular file (an sks to be exact), so Kay's answer didn't work. When I went to open my particular project, it would still crash.

I simply temporarily deleted the file. Then I opened the project, cleaned, and re-added the file, and all was well.

Not the answer you're looking for? Browse other questions tagged or ask your own question.