The builder pattern lets you abstract away the construction of objects or values that require a large number of parameters by using an intermediate representation—the builder. While very popular in Java, for example, I haven't seen it in action in recent pure Swift code bases, most likely as it is cumbersome to implement by hand.
We'll see in this section how to put the builder pattern into action, which problems it solves, and how you can leverage metaprogramming in order to deploy it efficiently through your code base.
In Swift, we have the nice benefit of having structs automatically generate their constructor. This saves a lot of boilerplate code when creating new instances of structs.
Let's consider this Article
struct. You could use this to represent an article for a blog, for example:
struct Article { let id: String let title: String let contents: String let author: String let date: Date var views: Int }
Creating new Article
instances is quite labor...