Scheme Script vs. Build Phase Script

匿名 (未验证) 提交于 2019-12-03 08:36:05

问题:

After I make a build I want to copy some files into my Xcode project.

I discovered that I could do this either in

  1. In "Build Phases" with a custom build step.

  2. I can also execute scripts before and after the different "tasks" in the Scheme editor:

    • Build (This is where I could add my script)
    • Run
    • Test
    • Profile
    • Analyze
    • Archive

I don't completely understand the differences / possible implications between the two approaches and I am wondering when to choose either approach. Thanks for clarification.

回答1:

After I make a build I want to copy some files into my Xcode project.

I assume you want to copy files to your build product, not the Xcode project.

There are several subtle differences between scheme and build phase scripts. Here are some of them:

  • Scheme scripts are part of the scheme, so sharing with other developers is more configurable. Build phase scripts on the other hand are part of the target and cannot be skipped simply by choosing another scheme.
  • Scheme scripts can run before the dependency checking. So you can use them to modify source files and get up to date results. This is not possible with build phase scripts.
  • The information passed to the script in environment variables differs slightly. Depending on what information you need you sometimes have to choose right kind of script.
  • Build phase scripts are run conditionally only if the build process succeeds until their place in the target.
  • Build phase scripts can be configured to only run when input files changed.


回答2:

There isn't much difference between the two, however you have more control where, in the build sequence, the build phases scripts are run and so this is preferable (for example you could modify files that have already been copied by standard Xcode build phases).

I always use Build Phases scripts myself and have never used Scheme scripts. They are more visible and more manageable.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!