FWStateMachine

@interface FWStateMachine : NSObject

有限状态机

  • 状态列表,只读

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSSet *_Nonnull states;
  • 事件列表,只读

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSSet *_Nonnull events;
  • 当前状态,只读

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) FWState *_Nonnull state;
  • 初始化状态,可写

    Declaration

    Objective-C

    @property (nonatomic, strong, nullable) FWState *initialState;
  • 添加状态

    Declaration

    Objective-C

    - (void)addState:(nonnull FWState *)state;

    Parameters

    state

    状态对象

  • 批量添加状态

    Declaration

    Objective-C

    - (void)addStates:(nonnull NSArray<FWState *> *)states;

    Parameters

    states

    状态数组

  • 从名称获取状态

    Declaration

    Objective-C

    - (nullable FWState *)stateNamed:(nonnull NSString *)name;

    Parameters

    name

    状态名称

    Return Value

    状态对象

  • 当前状态判断

    Declaration

    Objective-C

    - (BOOL)isState:(nullable id)state;

    Parameters

    state

    状态名称或对象

    Return Value

    判断结果

  • 添加事件

    Declaration

    Objective-C

    - (void)addEvent:(nonnull FWStateEvent *)event;

    Parameters

    event

    事件对象

  • 批量添加事件

    Declaration

    Objective-C

    - (void)addEvents:(nonnull NSArray<FWStateEvent *> *)events;

    Parameters

    events

    事件数组

  • 从名称获取事件

    Declaration

    Objective-C

    - (nullable FWStateEvent *)eventNamed:(nonnull NSString *)name;

    Parameters

    name

    事件名称

    Return Value

    事件对象

  • 激活并锁定状态机

    Declaration

    Objective-C

    - (void)activate;
  • 是否已激活

    Declaration

    Objective-C

    - (BOOL)isActive;

    Return Value

    激活状态

  • 事件是否可触发

    Declaration

    Objective-C

    - (BOOL)canFireEvent:(nullable id)event;

    Parameters

    event

    事件名称或对象

    Return Value

    是否可触发

  • 触发事件

    Declaration

    Objective-C

    - (BOOL)fireEvent:(nullable id)event;

    Parameters

    event

    事件名称或对象

    Return Value

    触发状态

  • 触发事件

    Declaration

    Objective-C

    - (BOOL)fireEvent:(nullable id)event withObject:(nullable id)object;

    Parameters

    event

    事件名称或对象

    object

    附加参数

    Return Value

    触发状态