Initializer

init(blockPredicate:action:)

Creates a rule whose predicate is evaluated and action is executed through the specified blocks.

Declaration

convenience init(blockPredicate predicate: @escaping (GKRuleSystem) -> Bool, action: @escaping (GKRuleSystem) -> Void)

Parameters

pred

A block that GameplayKit calls to evaluate the rule. The block takes a single parameter:

system

The rule system in whose context the rule is being evaluated.

The block returns a Boolean value—true if the predicate is satisfied (and the rule’s action should execute); false otherwise.

action

A block to be invoked after the rule’s predicate is satisfied. The block takes a single parameter:

system

The rule system in whose context the rule is executing its action.

Return Value

A new rule object.

Discussion

Rules created using this method can run arbitrary code in their predicate and action, but do not encode their predicate or action when archiving with the NSKeyedArchiver class. For archivable rules, use the methods listed in Creating Data-Driven Rules.