Skip to content

Commit

Permalink
Merge pull request blakewatters#24 from 9elements/master
Browse files Browse the repository at this point in the history
Extended TKState class to have an optional userInfo dictionary.
  • Loading branch information
blakewatters committed Jun 29, 2015
2 parents 7e16cb5 + 8b3ae2f commit 4c4b69f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
16 changes: 15 additions & 1 deletion Code/TKState.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@
///-----------------------

/**
Creates and returns a new state object with the specified name.
Creates and returns a new state object with the specified name and an optional userInfo dictionary.
@param name The name of the state. Cannot be blank.
@param userInfo An optional dictionary of user info.
@return A newly created state object with the specified name.
*/
+ (instancetype)stateWithName:(NSString *)name userInfo:(NSDictionary *)userInfo;

/**
Creates and returns a new state object with the specified name. This method uses stateWithName:userInfo: with nil as userInfo parameter.
@param name The name of the state. Cannot be blank.
@return A newly created state object with the specified name.
Expand All @@ -48,6 +57,11 @@
*/
@property (nonatomic, copy, readonly) NSString *name;

/**
An optional dictionary of user info.
*/
@property (nonatomic, copy, readonly) NSDictionary *userInfo;

///----------------------------------
/// @name Configuring Block Callbacks
///----------------------------------
Expand Down
9 changes: 8 additions & 1 deletion Code/TKState.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

@interface TKState ()
@property (nonatomic, copy, readwrite) NSString *name;
@property (nonatomic, copy, readwrite) NSDictionary *userInfo;
@property (nonatomic, copy) void (^willEnterStateBlock)(TKState *, TKTransition *);
@property (nonatomic, copy) void (^didEnterStateBlock)(TKState *, TKTransition *);
@property (nonatomic, copy) void (^willExitStateBlock)(TKState *, TKTransition *);
Expand All @@ -30,14 +31,20 @@ @interface TKState ()

@implementation TKState

+ (instancetype)stateWithName:(NSString *)name
+ (instancetype)stateWithName:(NSString *)name userInfo:(NSDictionary *)userInfo
{
if (! [name length]) [NSException raise:NSInvalidArgumentException format:@"The `name` cannot be blank."];
TKState *state = [self new];
state.name = name;
state.userInfo = userInfo;
return state;
}

+ (instancetype)stateWithName:(NSString *)name
{
return [self stateWithName:name userInfo:nil];
}

- (NSString *)description
{
return [NSString stringWithFormat:@"<%@:%p '%@'>", NSStringFromClass([self class]), self, self.name];
Expand Down

0 comments on commit 4c4b69f

Please sign in to comment.