---
title: "init(predicate:)"
framework: gameplaykit
role: symbol
role_heading: Initializer
path: "gameplaykit/gknspredicaterule/init(predicate:)"
---

# init(predicate:)

Initializes a rule with the specified predicate.

## Declaration

```swift
init(predicate: NSPredicate)
```

## Parameters

- `predicate`: A predicate to be tested when evaluating the rule.

## Return Value

Return Value A new predicate-based rule object.

## Discussion

Discussion Rules based on NSPredicate objects typically test information in the state dictionary of the rule system evaluating the rule. For example, the following code creates a rule you might use to determine whether an enemy character in a game behaves aggressively. This example presumes the rule system’s state dictionary contains an object for the key player, which in turn exposes a numeric value for the key health. The GKNSPredicateRule class by itself does nothing in its performAction(in:) method—to create actions for predicate-based rules, you must subclass GKNSPredicateRule. For more information, see GameplayKit Programming Guide.
