TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jan 2016 |
SPMSupports SPM | ✗ |
Maintained by Viet Phan.
It's small library written by Swift used as router management in iOS app.
To run the example project, clone the repo, and run pod install
from the Example directory first.
Define route via AppStateEvent
let appState = AppState(initialState: "root", events: [
AppStateEvent(name: "showLandingPage", from: "root", to: "landingPage"),
AppStateEvent(name: "showSignInPage", from: ["landingPage", "welcomePage"], to: "signInPage")
])
Register view controller as AppStateDelegate
for each state
appState.registerViewController(signInViewController, forState: "signInPage")
appState.registerViewController(welcomeViewController, forState: "welcomePage")
appState.registerViewController(homeViewController, forState: "landingPage")
extension SignInViewController: AppStateDelegate {
// will call when entering new state
func onEnterState(eventName: String, currentState: String, from: String, to: String, context: StateContext?) {
// got context, present - push - pop - animation new view, assign data from context ...
}
// will call when leaving current state
func onLeaveState(eventName: String, currentState: String, from: String, to: String, context: StateContext?)
}
appState.transitTo(<eventName>, context: context)
to update state and pass data through context
as [String: AnyObject]
typeE.g: App is at "landingPage" state (as HomeViewController
) and call appState.transitTo("showSignInPage")
, app would be update as "signInPage" state (as SignInViewController
).
AppState is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "AppState"
Viet Phan, [email protected]
AppState is available under the MIT license. See the LICENSE file for more info.