Created
November 13, 2020 14:25
-
-
Save manmal/5e05a29771a632f5aa68c0d5eabe2a2d 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
import Foundation | |
import PlaygroundSupport | |
import UIKit | |
enum PassingStructInInit { | |
struct A { | |
let b: B | |
} | |
struct B { | |
let doX: () -> Int | |
let doY: () -> String | |
static var standard: B { | |
B(doX: { 42 }, doY: { "Standard" }) | |
} | |
static var mock: B { | |
B(doX: { 0 }, doY: { "Mock" }) | |
} | |
} | |
struct ProductionUsage { | |
init() { | |
let b = B.standard | |
let a = A(b: b) | |
} | |
} | |
struct TestUsage { | |
init() { | |
let b = B.mock | |
let a = A(b: b) | |
} | |
} | |
} | |
enum PassingClosureInInit { | |
struct A { | |
let doX: () -> Int | |
} | |
struct B { | |
let doX: () -> Int | |
let doY: () -> String | |
static var standard: B { | |
B(doX: { 42 }, doY: { "Standard" }) | |
} | |
static var mock: B { | |
B(doX: { 0 }, doY: { "Mock" }) | |
} | |
} | |
struct ProductionUsage { | |
init() { | |
let b = B.standard | |
let a = A(doX: b.doX) | |
} | |
} | |
struct TestUsage { | |
init() { | |
let b = B.mock | |
let a = A(doX: b.doX) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment