Adding actions before Xcode's build
Have you ever got yourself in a situation where every time you make a change to your development pod you need to clean (Cmd + K) your project's build folder?
Well, Xcode Schemes have this nice feature that allows us to add actions before and after building, running, testing, profiling, analyzing, and archiving our app.
We’re interested here in adding actions to the build phase, but take a look at all these options available. We could, for instance, add a post-action to our archiving phase to generate a fat library.
By pressing Cmd + < , in the Xcode. Go to Build > Pre-actions. Press the + button to add a new run script action.
After that, select the scheme you want to run this configuration an insert the code below in the code area.
find ${BUILT_PRODUCTS_DIR} -name ‘your_framework_name*.framework’ -exec rm -rf {} \;
The $BUILT_PRODUCTS_DIR holds a reference to the product's built directory where we can find the built frameworks.
So we use the find command to find all files with .framework extension that have your_framework_name string in its name. Then we use the -exec rm -rf to remove those files.
Your configuration should like this.
That's it! Adding a pre-action was just an excuse to show a bunch of useful stuff that you can tweak and explore. Go ahead and take a look at the other features available.
Let me know what you think about this article in the comments :)