<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GameplayKit",
  "identifier" : "/documentation/GameplayKit/GKStateMachine/canEnterState(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKStateMachine(im)canEnterState:"
  },
  "title" : "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.

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

## Parameters

`stateClass`

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

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if a transition is allowed from the current state to a state of the specified class; otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

You build a state machine by creating a unique [`GKState`](/documentation/GameplayKit/GKState) subclass for each distinct state possible for the machine. The [`isValidNextState(_:)`](/documentation/GameplayKit/GKState/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`](/documentation/GameplayKit/GKStateMachine/currentState) property is `nil`. In this case, the [`canEnterState(_:)`](/documentation/GameplayKit/GKStateMachine/canEnterState(_:)) method always returns <doc://com.apple.documentation/documentation/Swift/true>. To choose and enter an initial state, use the [`enter(_:)`](/documentation/GameplayKit/GKStateMachine/enter(_:)) method.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)