Creates a data-driven rule with the specified predicate, whose action retracts a fact in the rule system evaluating the rule.
- iOS 9.0+
- macOS 10.11+
- Mac Catalyst 13.0+
- tvOS 9.0+
A predicate to be tested when the rule is evaluated.
An amount by which to decrease the fact’s membership grade if the rule’s predicate is satisfied.
A new rule object.
Rules created using this method encode their predicate and action when archived with the
NSKeyed class. You can use this feature to support saving and loading rules, editing rules in-game, or building tools that separate your gameplay design and game programming tasks.
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