如何在 Xcode 5 及更高版本中删除派生数据和清理项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27976787/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:29:41  来源:igfitidea点击:

How to Delete Derived Data and Clean Project in Xcode 5 and later?

iosxcodecachingxcode5

提问by norton9000

Is there a procedure I can follow that includes running a script in the terminal, to delete all the files under the derived data folder and reliably clean a project?

是否有我可以遵循的程序,包括在终端中运行脚本、删除派生数据文件夹下的所有文件并可靠地清理项目?

Sometimes, a project's assets don't always get updated to my simulator or device. It's mostly trial and error, and when I find that an old asset made its way into a test build, it's too late, not to mention embarrassing!

有时,项目的资产并不总是更新到我的模拟器或设备。这主要是反复试验,当我发现旧资产进入测试版本时,为时已晚,更不用说尴尬了!

I've looked at this question, but it seems a little outdated: How to Empty Caches and Clean All Targets Xcode 4

我看过这个问题,但它似乎有点过时: How to Empty Caches and Clean All Targets Xcode 4

I also checked out this question, but I don't want to waste time in Organizer, if I don't absolutely need to: How to "Delete derived data" in Xcode6?

我也检查了这个问题,但我不想在管理器中浪费时间,如果我不是绝对需要:如何在 Xcode6 中“删除派生数据”?

I've looked at other posts out there, but found nothing that solves the problem of reliably cleaning a project and saves time with a script.

我查看了那里的其他帖子,但没有发现可以解决可靠地清理项目并节省脚本时间的问题。

回答by Sheamus

It's basically a two-or-three-step process, which cleans the project of all cached assets.

它基本上是一个两到三步的过程,它清除所有缓存资产的项目。

Of course, if anyone uses this technique, and a project still does not show updated assets, then please add an answer! It's definitely possible that someone out there has encountered situations that require a step that I'm not including.

当然,如果有人使用这种技术,并且项目仍然没有显示更新的资产,那么请添加答案!绝对有可能有人遇到过需要我未包括的步骤的情况。

  1. Clean your project with Shift-Cmd-K
  2. Delete derived data by calling a shell script (details below), defined in your bash profile
  3. Uninstall the App from the Simulator or device.
  4. For certain types of assets, you may also have to reset the Simulator (under the iOS Simulator menu)
  1. 使用Shift- Cmd-清理您的项目K
  2. 通过调用 bash 配置文件中定义的 shell 脚本(详细信息如下)删除派生数据
  3. 从模拟器或设备卸载应用程序。
  4. 对于某些类型的资产,您可能还需要重置模拟器(在 iOS 模拟器菜单下)

To call the shell script below, simply enter enter the function name (in this case 'ddd') into your terminal, assuming it's in your bash profile. Once you've saved your bash profile, don't forget to update your terminal's environment if you kept it open, with the source command:
source ~/.bash_profile

要调用下面的 shell 脚本,只需在终端中输入函数名称(在本例中为“ddd”),假设它在您的 bash 配置文件中。保存 bash 配置文件后,请不要忘记使用 source 命令更新终端环境(如果您保持打开状态):
source ~/.bash_profile

ddd() {
    #Save the starting dir
    startingDir=$PWD

    #Go to the derivedData
    cd ~/Library/Developer/Xcode/DerivedData

    #Sometimes, 1 file remains, so loop until no files remain
    numRemainingFiles=1
    while [ $numRemainingFiles -gt 0 ]; do
        #Delete the files, recursively
        rm -rf *

        #Update file count
        numRemainingFiles=`ls | wc -l`
    done

    echo Done

    #Go back to starting dir
    cd $startingDir
}

I hope that helps, happy coding!

我希望有帮助,快乐编码!

回答by shmathur

Another way to delete derived data in Xcode is just by deleting the Derived Data folder. Here is a visual tutorial of how you can do that easily without using command line: https://www.youtube.com/watch?v=ueEMGXKDBAc

在 Xcode 中删除派生数据的另一种方法是删除派生数据文件夹。这是一个可视化教程,说明如何在不使用命令行的情况下轻松完成此操作:https: //www.youtube.com/watch?v=ueEMGXKDBAc