Skip to content

Instantly share code, notes, and snippets.

@mbrandonw
Created November 13, 2020 19:33
Show Gist options
  • Save mbrandonw/0346cec1fea37b37a25f7f463431fbdd to your computer and use it in GitHub Desktop.
Save mbrandonw/0346cec1fea37b37a25f7f463431fbdd to your computer and use it in GitHub Desktop.
protocol SomeProtocol {
func foo() -> Int?
}
struct Live: SomeProtocol {
func foo() -> Int? {
// do some work to return an integer
}
}
struct Mock: SomeProtocol {
let value: Int?
func foo() -> Int? {
self.value
}
}
// versus:
struct Something {
var foo: () -> Int?
}
let live = Something(foo: { /* do something to return an int */ })
let happyMock = Something(foo: { 42 })
let unhappyMock = Something(foo: { nil })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment