A rule for use in a rule system that uses a Foundation NSPredicate
object to evaluate itself.
SDKs
- iOS 9.0+
- macOS 10.11+
- Mac Catalyst 13.0+
- tvOS 9.0+
Framework
- Gameplay
Kit
Declaration
@interface GKNSPredicateRule : GKRule
Overview
The GKNSPredicate
class is a specialized subclass of the GKRule
class (which represents rules to be used by GKRule
objects). Custom subclasses of GKNSPredicate
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 GKRule
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 perform
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
Use the
GKRule
methodrule
orWith Predicate: asserting Fact: grade: rule
to create a rule that uses anWith Predicate: retracting Fact: grade: NSPredicate
object for evaluation and whose action asserts or retracts a fact in the containing rule system.Use the
GKRule
methodrule
method to quickly create a rule whose custom logic is contained in block objects.With Block Predicate: action: