Skip to content

Instantly share code, notes, and snippets.

View muuhoffman's full-sized avatar

Matt Hoffman muuhoffman

View GitHub Profile
@muuhoffman
muuhoffman / BuilderPattern.swift
Last active March 21, 2018 03:58
Protocol-Oriented Builder Pattern
/**
Describes a Model that can be built by a Builder
*/
protocol BuildableModel {
}
/**
Describes a Builder. Extends `class` so that set() calls can return self without the compiler complaining about an immutable value. This is for chaining set() and build() calls.
*/
protocol Builder: class {
@muuhoffman
muuhoffman / OldUserBuilder.swift
Last active August 28, 2017 18:50
The common way of using the Builder Pattern in Swift
struct UserSignUp {
var firstName: String
var lastName: String?
var username: String
var password: String
class Builder {
var firstName: String?
var lastName: String?
var username: String?