DEV Community

Cover image for Advanced iOS development - Build Phases Part 1
Omar Labib
Omar Labib

Posted on

Advanced iOS development - Build Phases Part 1

Have you ever come across this build error in Xcode..
Xcode build phase failure
I'm sure you have.
During my first years of iOS development, this has been one of the most ambiauious errors for me, I can only see that I've messed up somewhere in the codebase and I have to go and see what I've done wrong, however, after I got to know build phases better in Xcode this couldn't make more sense..

Build Phases

In Xcode build phases section is the scope where Xcode offers you the possibility to run custom scripts - known as run scripts - as part of the build process, these script can be tailored for any behavior you can think of. The cool thing though is that you can control the build process through this powerful script of you..
Let's better have an example..

For Starter, How can we add those run scripts?
Xcode build phase

  1. Head to you project file.
  2. Choose your app target.
  3. Navigate the build phases tab.
  4. Click the + button and choose New Run Script Phase

This will add a run script template for you..
Xcode Run Script

  1. You can give a cool name to your script.
  2. This is the path you shell on your machine.
  3. The Shell script that will be run during the building process.

Note: All these run scripts will run serially, and you can change the order by grabbing the run script and moving it up or down.
For our very first run script, we will be doing something very simple..
Just printing some message to the user..

Xcode build phase
This message however won't be printed to the log. Instead, you can access it through the build report.

Xcode Build Report

  1. Navigate to the report navigator.
  2. Choose your build of interest.
  3. Choose all messages tab.
  4. You will find the message printed.

Now let's tweak this build a little, let's break the build for no reason..

Image description
The key here is to exit the script with any value rather than zero, this will indeed fail the script and all the succeeding run scripts won't even run.

This will result in our friendly message we now understand its meaning.
Xcode Build Phase

So this is it for our first part, in the next part we will build upon our knowledge and develop a very useful run script to use in you apps, so stay tuned 😉

Top comments (0)