<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "TipKit",
  "identifier" : "/documentation/TipKit/Tips/Rule",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "TipKit"
    ],
    "preciseIdentifier" : "s:6TipKit4TipsO4RuleV"
  },
  "title" : "Rule"
}
-->

# Rule

A condition to meet before displaying a tip.

```
struct Rule
```

## Overview

Use rules to control when your tips display.

### Parameter Rules

[`Parameter`](/documentation/TipKit/Tips/Parameter) based rules track app state. For example, to display a tip when someone logs in:

1. Define the app state you want to track using the `@Parameter` macro.
2. Define a rule based on that app state using the `#Rule` macro.
3. Set the conditions for when the tip displays in the macro closure.

```swift
struct FavoriteLandmarkTip: Tip {
    // Define the app state you want to track.
    @Parameter
    static var userIsLoggedIn: Bool = false

    var rules: [Rule] {
        // Define a rule based on the app state.
        #Rule(Self.$userIsLoggedIn) {
            // Set the conditions for when the tip displays.
            $0 == true
        }
    }
}
```

### Event Rules

Event based rules track user interactions. For example, to display a tip only when a [`Event`](/documentation/TipKit/Tips/Event) occurs three or more times:

1. Define the user interaction you want to track as a [`Event`](/documentation/TipKit/Tips/Event) with a unique `id`.
2. Define a rule based on that interaction using a `#Rule` macro.
3. Set the conditions for when the tip displays in the macro closure.

```swift
struct FavoriteLandmarkTip: Tip {
    // Define the user interaction you want to track.
    static let didViewLandmark: Event = Event(id: "didViewLandmark")

    var rules: [Rule] {
        // Define a rule based on the interaction.
        #Rule(Self.didViewLandmark) {
            // Set the conditions for when the tip displays.
            $0.donations.count > 3
        }
    }
}
```

> Note: If no rules are defined within a tip content structure, the tip displays until dismissed or they exceed the threshold of their display frequency.

## Topics

### Creating parameters

[`Parameter`](/documentation/TipKit/Tips/Parameter)

A type that monitors the state of its wrapped value to reevaluate any dependent tip rules when the value changes.

### Creating events and adding donations

[`Event`](/documentation/TipKit/Tips/Event)

A repeatable user-defined action.



---

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)