<!--
{
  "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/GKRule/init(predicate:assertingFact:grade:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKRule(cm)ruleWithPredicate:assertingFact:grade:"
  },
  "title" : "init(predicate:assertingFact:grade:)"
}
-->

# init(predicate:assertingFact:grade:)

Creates a data-driven rule with the specified predicate, whose action asserts a fact in the rule system evaluating the rule.

```
convenience init(predicate: NSPredicate, assertingFact fact: any NSObjectProtocol, grade: Float)
```

## Parameters

`fact`

An object representing a fact to assert when the rule’s predicate is satisfied. (For details on facts in rule systems, see the [`facts`](/documentation/GameplayKit/GKRuleSystem/facts) property in [`GKRuleSystem`](/documentation/GameplayKit/GKRuleSystem).)

`grade`

An amount by which to increase the fact’s membership grade if the rule’s predicate is satisfied.

## Return Value

A new rule object.

## Discussion

Rules created using this method encode their predicate and action when archived with the <doc://com.apple.documentation/documentation/Foundation/NSKeyedArchiver> 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 <doc://com.apple.documentation/documentation/Foundation/NSPredicate> objects typically test information in the [`state`](/documentation/GameplayKit/GKRuleSystem/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 `health`.)

```swift
let healthTest = NSPredicate(format: "$player.health < 25")
let rule = GKRule(predicate: healthTest, assertingFact: "player_weak", grade: 0.5)
```

---

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)