Contents

Rule

A condition to meet before displaying a tip.

Declaration

struct Rule

Overview

Use rules to control when your tips display.

Parameter Rules

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.

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 occurs three or more times:

  1. Define the user interaction you want to track as a 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.

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
        }
    }
}

Topics

Creating parameters

Creating events and adding donations

Enumerations