Member-only story

Boost Your Swift Code : Reduce compile time

The Blue Prototype
3 min readMay 16, 2020

--

After going through lots of articles, I researched the things to improve swift compile time which can increase your xcode project build time. This article focused only on points, not a lengthy theory.

Get Started

1. Remove dead code

When you start working on a project, and as it evolves, code becomes unreachable to handle it. Then, find the dead code in the project and remove it.

  • Delete unused code
  • Delete unused files
  • Delete unused method parameters
  • Reduced conditional statements if not required

2. Benchmarking for extensions vs class method

Do the benchmarking for extensions & class methods. Both are different in compile time. If you want, you can read it more in depth here.

3. Use type annotations

Adding a type annotation to the variable tells the compiler that x represents a String. It does not have to infer anything here and the code is that much more readable to humans. The code builds faster and is easier to maintain.

let x : String = “This is type annotation example”

4. Avoid using ternary…

--

--

Responses (2)