A rule for use in a rule system that uses a Foundation NSPredicate object to evaluate itself.


@interface GKNSPredicateRule : GKRule


The GKNSPredicateRule class is a specialized subclass of the GKRule class (which represents rules to be used by GKRuleSystem objects). Custom subclasses of GKNSPredicateRule use an NSPredicate object to evaluate a rule, rather than requiring custom logic for evaluation as is the case with custom GKRule subclasses.

For more information about rules and rule systems, read Rule Systems in GameplayKit Programming Guide.

Subclassing Notes

GameplayKit evaluates rules in the context of a 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 performActionWithSystem: method to perform whatever actions should result when your rule is satisfied (that is, when its predicate property evaluates to true in the context of the provided rule system).

Alternatives to Subclassing


Creating a Predicate-Based Rule

- initWithPredicate:

Initializes a rule with the specified predicate.

Evaluating a Rule


A predicate to be tested when evaluating the rule.

- evaluatePredicateWithSystem:

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


Inherits From

See Also

Rule Systems


A rule to be used in the context of a rule system, with a predicate to be tested and an action to be executed when the test succeeds.


A list of rules, together with a context for evaluating them and interpreting results, for use in constructing data-driven logic or fuzzy logic systems.