Implementing the builder pattern

Before we show how we would use the builder pattern, let's look at how to create a complex structure without the builder pattern and the problems we run into.

The following code creates a structure named BurgerOld, and does not use the builder pattern:

struct BurgerOld { 
  var name: String 
  var patties: Int 
  var bacon: Bool 
  var cheese: Bool 
  var pickles: Bool 
  var ketchup: Bool 
  var mustard: Bool 
  var lettuce: Bool 
  var tomato: Bool 
  init(name: String, patties: Int, bacon: Bool, cheese: Bool,       pickles:Bool,ketchup: Bool,mustard: Bool,lettuce: Bool, tomato: Bool) { = name self.patties = patties self.bacon = bacon self.cheese = cheese self.pickles = pickles self.ketchup = ketchup self.mustard = mustard self.lettuce ...

Get Mastering Swift 4 - Fourth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.