O'Reilly logo

Mastering Swift 4 - Fourth Edition by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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) { self.name = name self.patties = patties self.bacon = bacon self.cheese = cheese self.pickles = pickles self.ketchup = ketchup self.mustard = mustard self.lettuce ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required