Skip to content

Commit

Permalink
Add support for multiple sub flow controllers
Browse files Browse the repository at this point in the history
This fixes #10.
  • Loading branch information
Jeehut committed Nov 19, 2018
1 parent 259799e commit fe5a2cd
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions Frameworks/Imperio/FlowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import UIKit

/// A class to be subclassed by flow controllers.
open class FlowController: NSObject {
var subFlowController: FlowController?
var subFlowControllers: [FlowController] = []
weak var superFlowController: FlowController?

/// Starts the flow from a given view controller.
Expand All @@ -18,19 +18,14 @@ open class FlowController: NSObject {
/// - Parameters:
/// - subFlowController: The sub flow controller to be added.
public func add(subFlowController: FlowController) {
// Clean up
self.subFlowController?.removeFromSuperFlowController()
subFlowController.removeFromSuperFlowController()

// Store new
self.subFlowController = subFlowController
subFlowControllers.append(subFlowController)
subFlowController.superFlowController = self
}

/// Removes this flow controller from its super flow controller.
public func removeFromSuperFlowController() {
subFlowController?.removeFromSuperFlowController()
superFlowController?.subFlowController = nil
subFlowControllers.forEach { $0.removeFromSuperFlowController() }
superFlowController!.subFlowControllers.removeAll { $0 == self }
superFlowController = nil
}
}

0 comments on commit fe5a2cd

Please sign in to comment.