Decouple your View Controllers with Flow Controllers
SignUpStep1VC.self --> SignUpStep2VC.self
- Decouples ViewControllers between them
- Leaves your View Controllers Clean
- Faster Compile times (less dependencies)
Picture a Flow
visually exactly like a Storyboard.
You have :
- An
initialViewController
where the flow starts. Links
between ViewControllersA
-->B
.- And
Data
that you can pass between themA
--onEvent(data)
-->B(data)
class SignupFlow: Flow {
override init() {
super.init()
initialViewController = SignUpStep1VC()
register(
SignUpStep1VC.self --> { SignUpStep2VC(user: $0) },
SignUpStep2VC.self --> { SignUpStep3VC(user: $0) },
SignUpStep3VC.self --> { SignUpStep4VC(user: $0) }
)
}
}
Here each View Controllers passes the User
model around.
func application(_ application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.start(flow: SignupFlow()) // Start Flow!
window?.makeKeyAndVisible()
return true
}