<!--
{
  "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/GKNSPredicateRule",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKNSPredicateRule"
  },
  "title" : "GKNSPredicateRule"
}
-->

# GKNSPredicateRule

A rule for use in a rule system that uses a Foundation <doc://com.apple.documentation/documentation/Foundation/NSPredicate> object to evaluate itself.

```
class GKNSPredicateRule
```

## Overview

The [`GKNSPredicateRule`](/documentation/GameplayKit/GKNSPredicateRule) class is a specialized subclass of the [`GKRule`](/documentation/GameplayKit/GKRule) class (which represents rules to be used by [`GKRuleSystem`](/documentation/GameplayKit/GKRuleSystem) objects). Custom subclasses of [`GKNSPredicateRule`](/documentation/GameplayKit/GKNSPredicateRule) use an <doc://com.apple.documentation/documentation/Foundation/NSPredicate> object to evaluate a rule, rather than requiring custom logic for evaluation as is the case with custom [`GKRule`](/documentation/GameplayKit/GKRule) subclasses.

For more information about rules and rule systems, read [Rule Systems](https://developer.apple.com/library/archive/documentation/General/Conceptual/GameplayKit_Guide/RuleSystems.html#//apple_ref/doc/uid/TP40015172-CH10) in [GameplayKit Programming Guide](https://developer.apple.com/library/archive/documentation/General/Conceptual/GameplayKit_Guide/index.html#//apple_ref/doc/uid/TP40015172).

### Subclassing Notes

GameplayKit evaluates rules in the context of a [`GKRuleSystem`](/documentation/GameplayKit/GKRuleSystem) object, so custom rule classes should be *functional*—that is, they generally should not carry independent state that affects their predicate or action.

#### Methods to Override

Override the [`performAction(in:)`](/documentation/GameplayKit/GKRule/performAction(in:)) method to perform whatever actions should result when your rule is satisfied (that is, when its [`predicate`](/documentation/GameplayKit/GKNSPredicateRule/predicate) property evaluates to true in the context of the provided rule system).

#### Alternatives to Subclassing

- Use the [`GKRule`](/documentation/GameplayKit/GKRule) method [`init(predicate:assertingFact:grade:)`](/documentation/GameplayKit/GKRule/init(predicate:assertingFact:grade:)) or [`init(predicate:retractingFact:grade:)`](/documentation/GameplayKit/GKRule/init(predicate:retractingFact:grade:)) to create a rule that uses an <doc://com.apple.documentation/documentation/Foundation/NSPredicate> object for evaluation and whose action asserts or retracts a fact in the containing rule system.
- Use the [`GKRule`](/documentation/GameplayKit/GKRule) method [`init(blockPredicate:action:)`](/documentation/GameplayKit/GKRule/init(blockPredicate:action:)) method to quickly create a rule whose custom logic is contained in block objects.

## Topics

### Creating a Predicate-Based Rule

[`-  initWithPredicate:`](/documentation/GameplayKit/GKNSPredicateRule/init(predicate:))

Initializes a rule with the specified predicate.

### Evaluating a Rule

[`predicate`](/documentation/GameplayKit/GKNSPredicateRule/predicate)

A predicate to be tested when evaluating the rule.

[`-  evaluatePredicateWithSystem:`](/documentation/GameplayKit/GKNSPredicateRule/evaluatePredicate(in:))

Returns a Boolean value indicating whether the rule’s predicate has been satisfied in the context of the specified rule system.

## Relationships

### Conforms To

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Equatable`](/documentation/Swift/Equatable)

### Inherits From

[`GKRule`](/documentation/GameplayKit/GKRule)

---

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)