Latest 1.0.0
Homepage https://github.com/albertodebortoli/ADBStateMachine
License New BSD License
Platforms ios 7.0, requires ARC
Authors

A proper thread-safe state machine for Objective-C.

Simple usage:

  • import the files in the Classes folder in your project or install via CocoaPods adding pod "ADBStateMachine" to your Podfile
  • import ADBStateMachine.h in your class
  • create a state machine with the initial state and assign it to a property
self.stateMachine = [[ADBStateMachine alloc] initWithInitialState:@"Idle" callbackQueue:nil];
  • create transitions and add them to the state machine (the state machine will automatically recognize the new states)
ADBStateMachineTransition *t1 = [[ADBStateMachineTransition alloc] initWithEvent:@"start"
                                                                       fromState:@"Idle"
                                                                         toState:@"Started"
                                                                        preBlock:^{
                                                                            NSLog(@"Gonna move from Idle to Started!");
                                                                        }
                                                                       postBlock:^{
                                                                            NSLog(@"Just moved from Idle to Started!");
                                                                        }];

ADBStateMachineTransition *t2 = [[ADBStateMachineTransition alloc] initWithEvent:@"pause"
                                                                       fromState:@"Started"
                                                                         toState:@"Idle"
                                                                        preBlock:nil
                                                                       postBlock:nil];

[stateMachine addTransition:t1];
[stateMachine addTransition:t2];
  • process events like so
[stateMachine processEvent:@"start"];
[stateMachine processEvent:@"pause"];

Latest podspec

{
    "name": "ADBStateMachine",
    "version": "1.0.0",
    "platforms": {
        "ios": "7.0"
    },
    "summary": "A proper thread-safe state machine for Objective-C.",
    "homepage": "https://github.com/albertodebortoli/ADBStateMachine",
    "authors": {
        "Alberto De Bortoli": "[email protected]"
    },
    "source": {
        "git": "https://github.com/albertodebortoli/ADBStateMachine.git",
        "tag": "1.0.0"
    },
    "license": {
        "type": "New BSD License",
        "file": "LICENSE"
    },
    "source_files": "ADBStateMachine/Classes/*.{h,m}",
    "requires_arc": true
}

Pin It on Pinterest

Share This