---
title: "canEnterState(_:)"
framework: gameplaykit
role: symbol
role_heading: Instance Method
path: "gameplaykit/gkstatemachine/canenterstate(_:)"
---

# 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

```swift
func canEnterState(_ stateClass: AnyClass) -> Bool
```

## Parameters

- `stateClass`: The class of state for which to determine whether a transition is allowed.

## Return Value

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

## Discussion

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

- [currentState](gameplaykit/gkstatemachine/currentstate.md)
- [enter(_:)](gameplaykit/gkstatemachine/enter(_:).md)
- [update(deltaTime:)](gameplaykit/gkstatemachine/update(deltatime:).md)
