[![CI Status](http://img.shields.io/travis/Viet Phan/AppState.svg?style=flat)](https://travis-ci.org/Viet Phan/AppState)
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") ])
- name: event name
- from: source state
- to: destination state
- E.g: If app is at "root" state (viewController), app could only update to "landingPage" state. If app is at "landingPage" or "welcomePage" state, then app could update to "signInPage" state
-
Register view controller as
AppStateDelegate
for each stateappState.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?) }
- Call
appState.transitTo(<eventName>, context: context)
to update state and pass data throughcontext
as[String: AnyObject]
type
- Call
-
E.g: App is at "landingPage" state (as
HomeViewController
) and callappState.transitTo("showSignInPage")
, app would be update as "signInPage" state (asSignInViewController
).
AppState is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "AppState"
Viet Phan, vietphxfce@gmail.com
AppState is available under the MIT license. See the LICENSE file for more info.