init(id:)
Creates an event with an associated donation value.
Declaration
init(id: String)Parameters
- id:
Unique identifier for persisting the event and its donations.
Creating an event
Create an event when you want display a tip based on an action that can occur one or more times in your app (such as a user logging in). Then use donate() to donate to the event when the action occurs, increasing the event count by one.
struct LandmarkDetailView: View {
let landmark: Landmark
var body: some View {
VStack {
Text(landmark.name)
Text(landmark.description)
}
.task {
let donationInfo = DidViewLandmark(landmarkName: landmark.name)
await Self.didViewLandmark.donate(donationInfo)
}
}
static let didViewLandmark = Event(id: "didViewLandmark")
}Adding event rules
Add tip display rules using the #Rule macro to prevent a tip from being displayed until an event has been donated a specific number of times.
struct FavoriteLandmarkTip: Tip {
var rules: [Rule] {
// Tip will only display when the didViewLandmark event has been donated 3 or more times.
#Rule(LandmarkDetailView.didViewLandmark) {
$0.donations.count >= 3
}
}
}