Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
State Chart Framework
Branch: master
Pull request Compare This branch is 10 commits behind ronaldmannak:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
YBStatechart.xcodeproj
YBStatechart
YBStatechartTests
.gitignore
LICENSE
README.md
YBStatechart.podspec

README.md

YBStatechart

YBStatechart is a statechart framework. Statecharts are a formalized type of finite state machine, which resulted from David Harel's research on software architecture design for aircraft systems in 1986. His white paper article is well worth the (somewhat lengthy) read.

The statechart design pattern is also used in the SproutCore web front-end framework. They wrote a blog article about statecharts compared to the model-view-controller pattern.

Contrived example

A very simple example of a chart with only 2 substates:

YBState *rootState = [YBState stateWithName:@"rootState"];
YBState *loggedOut = [YBState stateWithName:@"loggedOut"];
YBState *loggedIn = [YBState stateWithName:@"loggedIn"];

[loggedIn onEnterState:^(YBState *_self) {
    // executed when loggedIn state is entered / activated
}];

[loggedIn onExitState:^(YBState *_self) {
    // executed when loggedIn state is exited / deactivated
}];

[loggedIn on:@"buttonPress" doBlock:^(YBState *_self) {
    // executed only when loggedIn is active
    // AND 
    // [statechart buttonPress] or [statechart dispatchEvent:@"buttonPress"] got called
}];

YBStatechart *statechart = [[YBStatechart alloc] init];
statechart.rootState = rootState;
[statechart activate];

A state can be activated by calling one of the -activateState...: methods on the statechart, e.g.:

[statechart activateState:loggedIn];

Now the statechart object is able to respond to arbitrary Objective-C messages, which will be dispatched as "events" to all the active substates and their active substates, ... For example:

[statechart buttonPress];

This will call the block handlers associated with the named event buttonPress, but only on states that are active at this moment.

For more useful examples, please read David Harel's white paper.

Installation

CocoaPods is the recommended way to install YBStatechart

Example podfile:

pod 'YBLStatechart', '1.0.0'

License

YBLStatechart is licensed under the Apache Software License, 2.0 ("Apache 2.0")

Something went wrong with that request. Please try again.