Skip to content

Commit

Permalink
Extended TKState class to have an optional userInfo dictionary.
Browse files Browse the repository at this point in the history
Declared additional constructor accepting userInfo as parameter and kept old constructor for backwards compatibility.
  • Loading branch information
gretzki committed Oct 17, 2014
1 parent 5d7b121 commit 8b3ae2f
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 = [TKState 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 8b3ae2f

Please sign in to comment.