diff --git a/Code/TKState.h b/Code/TKState.h index 15a3dc8..a6d2025 100644 --- a/Code/TKState.h +++ b/Code/TKState.h @@ -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. @@ -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 ///---------------------------------- diff --git a/Code/TKState.m b/Code/TKState.m index 4896fa5..2ec6c24 100644 --- a/Code/TKState.m +++ b/Code/TKState.m @@ -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 *); @@ -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];