如何让 Xcode 不自动打开以前打开的项目

所以,我打开了一个旧项目的 xib 文件,它导致了崩溃。这不是重点。问题是,现在当我重新启动 Xcode 时,它试图打开所有以前打开的项目(和文件) ,然后崩溃再次发生。Xcode 在哪里存储以前打开的文件列表,如何让它在没有任何打开项目的情况下启动“清理”?

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

22398 次浏览

不要查找包含 Xcode 设置的文件,而是使用 defaults命令查看设置本身:

% 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 ""

或者,您可以使用 defaults read命令将设置转储到一个文本文件中,编辑该文件,然后使用 defaults write更新设置:

% defaults read com.apple.xcode > xcsettings.plist
// edit xcsettins.plist with your favorite editor
% defaults write com.apple.xcode < xcsettings.plist

给定目录 ~/Document/Projects/MyProject 中的项目名称“ MyProject”,执行以下操作:

  1. cd ~/Documents/Projects
  2. mv MyProject MyProject.x
  3. open -a Xcode
  4. 关闭 MyProject (选项 + 命令 + W)
  5. mv MyProject.x MyProject
  6. open -a Xcode

这解决了我的崩溃... 然而我的故事书是腐败的。幸运的是,时间机器备份的文件夹是完整的,我刚刚恢复它。

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 这篇文章.

基本上,我使用以下命令从终端打开了另一个 Xcode 项目(尽管它可以是任何文件) :

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

这成功地启动了标准的“欢迎使用 Xcode”对话框。希望对您有所帮助!

我最近也遇到过类似的问题。我尝试了上面的方法,可以从命令行启动 Xcode,但是一旦我尝试从查找器打开,它就会尝试打开“坏”文档并挂起。

我最终通过删除以下内容解决了这个问题:

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

这好像帮我修好了。

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.

不是特定于 Xcode 的:

请确保在 System Preferences > General下选中了 Close windows when quitting an application复选框。

我可以用 Mavericks 中的下面的命令行做到这一点:

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

对我来说,这并不是一个项目导致了启动时的崩溃,而是一个特定的文件(确切地说是一个 sks) ,所以 Kay 的回答不起作用。当我打开我的特定项目时,它仍然会崩溃。

我只是暂时删除了文件。然后我打开项目,清理,并重新添加文件,一切都很好。

通过运行以下命令可以阻止 Xcode 打开最后一个项目:

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

This and other useful commands are here.

I think Xcode may update its cache when you quit. It solved my issue to:

  1. 关闭项目
  2. 退出 Xcode
  3. 重新打开 Xcode。