---
title: Event
framework: tipkit
role: symbol
role_heading: Type Alias
path: tipkit/tip/event
---

# Event

A repeatable user-defined action.

## Declaration

```swift
typealias Event = Tips.Event
```

## Overview

Overview Use an event when you want to track 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. note: In order to remain performant, by default events only query their most recent 1000 donations. Creating an event with no associated donation value The example below creates a landmarksAppDidOpen event with no associated donation value and donates it anytime ContentView appears: struct LandmarkTips: App {     static let landmarksAppDidOpen = Tips.Event(id: "landmarksAppDidOpen")

var body: some Scene {         WindowGroup {             ContentView()                 .onAppear { Self.landmarksAppDidOpen.sendDonation() }         }     } } The example below creates a display rule for LandmarkFeatureTip based on the landmarksAppDidOpen event. struct LandmarkFeatureTip: Tip {     var rules: [Rule] {         // Tip will only display when the landmarksAppDidOpen event has been donated 3 or more times in the last week.         #Rule(LandmarkTips.landmarksAppDidOpen) {             $0.donations.donatedWithin(.week).count >= 3         }     } } Creating an event with an associated donation value The example below creates a didViewLandmarkDetail event with an associated donation value and donates it anytime the LandmarkDetail appears: struct LandmarkDetail: View {     static let didViewLandmarkDetail = Tips.Event<DidViewLandmark>(id: "didViewLandmarkDetail")

struct DidViewLandmark: Codable, Sendable {         let landmarkID: Int         let landmarkName: String     }

var landmark: Landmark

var body: some View {         ScrollView {             MapView(coordinate: landmark.locationCoordinate)         }         .onAppear {             Self.didViewLandmarkDetail.sendDonation(.init(landmarkID: landmark.id, landmarkName: landmark.name))         }     } } The example below creates a display rule for LandmarkDetailTip based on the didViewLandmarkDetail event. struct LandmarkDetailTip: Tip {     var rules: [Rule] {         // Tip will only display when the didViewLandmarkDetail has been donated 3 or more times for landmarks not named "Wilbere Bowl".         #Rule(LandmarkDetail.didViewLandmarkDetail) {             $0.donations.filter({ $0.landmarkName != "Wilbere Bowl" }).count > 3         }     } } Filtering an event’s donations TipKit provides methods on Sequence for filtering an event’s donations within rule predicates. Use Swift/Sequence/donatedWithin(_:) to filter donations by recency: #Rule(AppEvents.didLogin) {     $0.donations.donatedWithin(.week).count >= 3 } Use Swift/Sequence/largestSubset(groupedBy:) and Swift/Sequence/smallestSubset(groupedBy:) to find the most or least frequent donation values: #Rule(LandmarkDetail.didViewLandmarkDetail) {     // Show tip when the most-viewed landmark has been viewed 5+ times.     $0.donations.largestSubset(groupedBy: \.landmarkID).count >= 5 } These methods can be combined to build complex eligibility conditions: #Rule(LandmarkDetail.didViewLandmarkDetail) {     // Show tip when the least-viewed landmark in the past month has been viewed at least twice.     $0.donations.donatedWithin(.month).smallestSubset(groupedBy: \.landmarkID).count >= 2 }

## Topics

### Initializers

- [init(id:)](tipkit/tips/event/init(id:)-99edo.md)
- [init(id:donationLimit:)](tipkit/tips/event/init(id:donationlimit:)-7tgi1.md)

### Initializers with a donation value

- [init(id:)](tipkit/tips/event/init(id:)-3edd4.md)
- [init(id:donationLimit:)](tipkit/tips/event/init(id:donationlimit:)-1d1hy.md)

### Donations

- [Donation](tipkit/tips/event/donation.md)
- [donations](tipkit/tips/event/donations.md)

### Add Donations

- [donate()](tipkit/tips/event/donate().md)
- [donate(_:)](tipkit/tips/event/donate(_:).md)
- [sendDonation(_:)](tipkit/tips/event/senddonation(_:).md)
- [sendDonation(_:_:)](tipkit/tips/event/senddonation(_:_:).md)

### Delete Donations

- [deleteDonations()](tipkit/tips/event/deletedonations().md)

## See Also

### Related Documentation

- [Rule](tipkit/tips/rule.md)
