Skip to content

Instantly share code, notes, and snippets.

@mikelikespie
Created June 16, 2016 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikelikespie/c54a017677265322df7eb785d9f36345 to your computer and use it in GitHub Desktop.
Save mikelikespie/c54a017677265322df7eb785d9f36345 to your computer and use it in GitHub Desktop.
/// Does something special that ViewController_A wants
struct Service_A {
func doSomething() {
}
}
/// Does something special that ViewController_B wants
struct Service_B {
func doSomething() {
}
}
/// Does something special that ViewController_C wants
struct Service_C {
func doSomething() {
}
}
/// Does something special that ViewController_D wants
struct Service_D {
func doSomething() {
}
}
class ViewController : UIViewController {
init() {
super.init(nibName: nil, bundle: nil)
}
/// make it so we can have a simple example w/o stupid constructors
@available(*, unavailable)
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
/// Responsible for calling serviceA then presenting ViewController_B
class ViewController_A : ViewController {
let serviceA: Service_A
let serviceB: Service_B
let serviceC: Service_C
let serviceD: Service_D
init(
serviceA: Service_A,
serviceB: Service_B,
serviceC: Service_C,
serviceD: Service_D
) {
self.serviceA = serviceA
self.serviceB = serviceB
self.serviceC = serviceC
self.serviceD = serviceD
super.init()
}
func showNestedViewController() {
serviceA.doSomething()
presentViewController(
ViewController_B(
serviceB: serviceB,
serviceC: serviceC,
serviceD: serviceD
),
animated: true,
completion: nil
)
}
}
/// Responsible for calling serviceB then presenting ViewController_C
class ViewController_B : ViewController {
let serviceB: Service_B
let serviceC: Service_C
let serviceD: Service_D
init(
serviceB: Service_B,
serviceC: Service_C,
serviceD: Service_D
) {
self.serviceB = serviceB
self.serviceC = serviceC
self.serviceD = serviceD
super.init()
}
func showNestedViewController() {
serviceB.doSomething()
presentViewController(
ViewController_C(
serviceC: serviceC,
serviceD: serviceD
),
animated: true,
completion: nil
)
}
}
/// Responsible for calling serviceC then presenting ViewController_D
class ViewController_C : ViewController {
let serviceC: Service_C
let serviceD: Service_D
init(
serviceC: Service_C,
serviceD: Service_D
) {
self.serviceC = serviceC
self.serviceD = serviceD
super.init()
}
func showNestedViewController() {
serviceC.doSomething()
presentViewController(
ViewController_D(
serviceD: serviceD
),
animated: true,
completion: nil
)
}
}
/// Responsible for calling serviceC then presenting ViewController_D
class ViewController_D : ViewController {
let serviceD: Service_D
init(
serviceD: Service_D
) {
self.serviceD = serviceD
super.init()
}
func doSomething() {
serviceD.doSomething()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment