Scheme Script vs. Build Phase Script
Asked Answered
S

2

16

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.

Success answered 25/10, 2012 at 9:47 Comment(0)
R
12

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.
Rhachis answered 25/10, 2012 at 10:19 Comment(1)
is it possible to say, run SwiftLint from a scheme script? When you do it via a build script it provides syntax hilighting for linting issues. I have not been successful at managing to get the same working from a scheme script. Reason I am asking is because swift packages do not have build scripts.Shortening
E
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.

Eglantine answered 25/10, 2012 at 9:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.