Created
November 13, 2020 19:33
-
-
Save mbrandonw/0346cec1fea37b37a25f7f463431fbdd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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