Reduce swift app build time and code optimization.

While working on large product based application i was figured out application is taking more time to build the app. So my next target was to reduce build and also code optimization. 
In my case, the initial aim was to just identify and fix the most time consuming areas with using Build Time Analyzer for Xcode.

How to setup Build Time Analyzer for Xcode.

Go to this link and download or clone the project. After this you just need to open that project into xcode and Press CMD + B to build the project.

Once build is done you need to Archive the build.

Archive the build

After completion of archive you need to export this build and select option as Export as a macOS App.

Now save it on your location and open that folder and install the application. Thats it.

Now big question here is how this app will identify our app and generate analysis report.

Follow this instruction

We to add custom flag on our application.
1. Select your target and go to Build Settings -> Swift Compiler -> Other Swift Flags and add this code -Xfrontend -debug-time-function-bodies.
Ensure that below flags are added to your target’s Build Settings.

2. Clean your project (CMD + Shift +K)

3. Build your project (CMD + B) and wait for it to complete.

After build completion go to Build Time Analyzer App and click on your app.

Now you can see the report generated by Build Time Analyzer App and analyze which function and code is taking more time. Based on that you can optimize your code and reduce the build time.

Make sure your are following correct swift syntax format. Also you need to use time consuming functions.
Use guard instant of if-else statement.


Hope you learned something new today.


If you enjoyed reading this post, please share and recommend it so others can find it too 💚💚💚💚💚💚 !!!!

You can follow me on Medium for fresh articles. Also, connect with me on LinkedIn.

If you have any comment, question, or recommendation, feel free to post them in the comment section below!