Rule
A condition to meet before displaying a tip.
Declaration
typealias Rule = Tips.RuleOverview
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:
Define the app state you want to track using the
@Parametermacro.Define a rule based on that app state using the
#Rulemacro.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:
Define the user interaction you want to track as a Event with a unique
id.Define a rule based on that interaction using a
#Rulemacro.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
}
}
}