The builder pattern in a nutshell

In conclusion, the builder pattern can be very powerful for a very particular use case in Swift. You should use it when you have an object construction that can span over time, and where it's cleaner to pass your builder around instead of aggregating all partial values.

It makes a lot of sense in Swift to leverage this pattern, instead of polluting your structs or classes with optionals.

To find out whether the builder is the right solution for you, follow these steps:

  1. Identify whether there are partial objects created in your app, or large structs.
  2. Implement your builder object as a nested class, or (better) use Sourcery and generate the code automatically.
  3. Replace the occurrences of your partial object with the builder in your code, and pass the builder around in your code.