Contents

canEnterState(_:)

Returns a Boolean value indicating whether it is valid for the state machine to transition from its current state to a state of the specified class.

Declaration

func canEnterState(_ stateClass: AnyClass) -> Bool

Parameters

  • stateClass:

    The class of state for which to determine whether a transition is allowed.

Return Value

true if a transition is allowed from the current state to a state of the specified class; otherwise false.

Discussion

You build a state machine by creating a unique GKState subclass for each distinct state possible for the machine. The isValidNextState(_:) method of each state object determines which other states a state machine is allowed to transition into from that state.

A newly created state machine’s currentState property is nil. In this case, the canEnterState(_:) method always returns true. To choose and enter an initial state, use the enter(_:) method.

See Also

Working with States