Integrating your calendar app with Apple Intelligence
At a glance
| Item | Summary |
|---|---|
| Purpose | Adopt calendar-domain App Intents schemas so people can create, find, update, open, and delete events with Siri, and test those intents with AppIntentsTesting. |
| App architecture | A SwiftUI app whose views and App Intents both route data work through one @MainActor @Observable CalendarManager singleton that owns the SwiftData container and a Spotlight index. |
| Main patterns | Singleton-style shared instances (CalendarManager.shared, NavigationManager.shared; initializers stay internal), App Intents dependency injection (AppDependencyManager + @Dependency), observable navigation state. |
| Project style | Folders by role: AppIntents/ (entities, intents, debug-only test intents), Managers/, Model/ (SwiftData), Views/, plus a separate CometCalUITests target. |
| Execution model | Manager, entity queries, and intent perform() methods are main-actor isolated; Spotlight indexing and intent donation run in fire-and-forget Task {} blocks created inside main-actor methods. |
| State/event model | SwiftData @Query drives lists; NavigationManager @Observable flags drive sheets and programmatic navigation; intents mutate data through the manager. |
| Key frameworks/packages | AppIntents, SwiftData, CoreSpotlight, GeoToolbox, SwiftUI; the UI-test target imports AppIntentsTesting and XCTest. No Swift package manifest. |
Project structure
CometCal/
├── CometCalApp.swift app entry, dependency registration
├── AppIntents/
│ ├── Entities/ EventEntity, CalendarEntity, AttendeeEntity + queries
│ ├── Intents/ Create/Update/Delete/Open event, CreateCalendar
│ └── TestSupport/ #if DEBUG intents used by UI tests
├── Managers/
│ ├── CalendarManager.swift SwiftData CRUD, Spotlight, donations
│ ├── CalendarManager+*.swift contacts, event updates, seed data
│ └── NavigationManager.swift observable sheet/navigation flags
├── Model/ @Model types with `entity` bridges
└── Views/ SwiftUI screens and EventSnippetView
CometCalUITests/
├── Helpers/BaseTestCase.swift IntentDefinitions lookup
└── *Tests.swift intent, query, Spotlight, annotation tests
Structure observations
CalendarManageris split across four files by concern; extensions such asCalendarManager+EventUpdates.swiftkeep helper logic beside the core CRUD type (CometCal/Managers/CalendarManager+EventUpdates.swift:12).- Test-only intents are compiled out of release builds with
#if DEBUG(CometCal/AppIntents/TestSupport/ResetTestDataIntent.swift:7). - Each SwiftData model exposes an
entitycomputed property that converts it into its App Intents entity (CometCal/Model/EventModel.swift:130).
Overall architecture
flowchart LR
App["CometCalApp"] -->|registers| Deps["AppDependencyManager"]
App --> List["CalendarListView"]
List -->|"@Query"| Store["SwiftData ModelContainer"]
List --> Nav["NavigationManager.shared"]
Views["Edit/Create views"] --> Manager["CalendarManager.shared"]
Siri["Siri / App Intents runtime"] --> Intents["Intents and entity queries"]
Intents -->|"@Dependency"| Manager
Manager --> Store
Manager --> Spotlight["CSSearchableIndex"]
Manager --> Donation["IntentDonationManager"]
Reference code
CometCal/CometCalApp.swift:16 — CometCalApp
@main
struct CometCalApp: App {
init() {
let manager = CalendarManager.shared
AppDependencyManager.shared.add(dependency: manager)
}
var body: some Scene {
WindowGroup {
CalendarListView()
}
.modelContainer(CalendarManager.shared.modelContainer)
}
}Interpretation
The app entry registers the same CalendarManager instance with the App Intents dependency system and supplies its modelContainer to the SwiftUI scene, so views reading with @Query and intents writing through the manager share one SwiftData store. Views reach the manager directly through CalendarManager.shared (CometCal/Views/EditEventView.swift:34), while intents receive it through @Dependency (CometCal/AppIntents/Intents/CreateEventIntent.swift:25). Inference: two access paths to one instance keep intents free of a hard-coded global while views stay simple.
Ownership and state
classDiagram
CalendarManager *-- ModelContainer : creates
CalendarManager *-- CSSearchableIndex : creates
CometCalApp --> CalendarManager : registers shared
CreateEventIntent o-- CalendarManager : @Dependency
CalendarListView o-- NavigationManager : @State shared
EventModel --> EventEntity : entity bridge
Ownership evidence
CometCal/Managers/CalendarManager.swift:18 — CalendarManager
@MainActor @Observable
final class CalendarManager {
// MARK: Static
static let shared = CalendarManager()
// MARK: Properties
let modelContainer: ModelContainer
var modelContext: ModelContext
nonisolated(unsafe) let searchableIndex: CSSearchableIndex
// MARK: Life cycle
init() {
guard let container = try? ModelContainer(
for: CalendarModel.self, EventModel.self, AttendeeModel.self, ContactModel.self
) else {
fatalError("Failed to create the model container.")
}
self.modelContainer = container
self.modelContext = container.mainContext
self.searchableIndex = CSSearchableIndex(name: "com.cometcal.index")
try? seedDataIfNeeded()
}
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
CalendarManager (static shared) |
ModelContainer, main ModelContext |
Creates and retains | Manager methods insert, delete, and save (CometCal/Managers/CalendarManager.swift:169) |
CalendarManager |
CSSearchableIndex |
Creates and retains | Manager Task blocks index or delete entities |
NavigationManager (static shared) |
showingCreateEvent, selectedEventID, sheet flags |
Owns observable state | openEvent, openCalendarManager, and views via bindings (CometCal/Managers/NavigationManager.swift:31) |
CalendarListView |
NavigationManager.shared, NavigationPath |
Holds the shared instance in @State; owns the path |
Appends selectedEventID and clears it (CometCal/Views/CalendarListView.swift:97) |
EventModel / CalendarModel |
EventEntity / CalendarEntity value |
Builds a fresh entity per access | Read-only snapshot for App Intents |
Concurrency, scheduling, and thread safety
Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.
| Concern | Source mechanism | Verified placement or handoff | Evidence |
|---|---|---|---|
| Main-actor isolation | @MainActor on the class |
All CalendarManager state and CRUD methods, including the SwiftData main context |
CometCal/Managers/CalendarManager.swift:13 |
| Main-actor isolation | @MainActor on queries and perform() |
Entity queries and intent bodies call the manager synchronously on the main actor | CometCal/AppIntents/Entities/CalendarEntity.swift:38, CometCal/AppIntents/Intents/CreateEventIntent.swift:30 |
| Task creation | Plain Task {} inside a main-actor method |
Spotlight indexing and intent donation; tasks inherit the manager’s isolation and are not stored or cancelled | CometCal/Managers/CalendarManager.swift:173, CometCal/Managers/CalendarManager+EventUpdates.swift:79 |
| Shared-state escape | nonisolated(unsafe) |
searchableIndex is exempted from actor checking; the source adds no lock or queue around it |
CometCal/Managers/CalendarManager.swift:24 |
| Navigation state | @MainActor @Observable |
Sheet and selection flags mutated by views and OpenEventIntent |
CometCal/Managers/NavigationManager.swift:9 |
Reference code
CometCal/Managers/CalendarManager.swift:173 — createEvent side effects
modelContext.insert(event)
try modelContext.save()
// Index the event in Spotlight.
Task {
try? await searchableIndex.indexAppEntities([event.entity])
}The save completes synchronously before the indexing task is created; errors from indexing and donation are discarded with try?. Inference: fire-and-forget keeps intent latency low at the cost of silent Spotlight failures.
State propagation, frameworks, and dependencies
Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.
| Category | Mechanism or module | Verified role | Evidence |
|---|---|---|---|
| State propagation | SwiftData @Query |
The event list re-renders from the shared container after intent or UI writes | CometCal/Views/CalendarListView.swift:15 |
| State propagation | @Observable + @State binding |
NavigationManager flags present sheets; onChange turns selectedEventID into a path push |
CometCal/Views/CalendarListView.swift:95 |
| Dependency registration | AppDependencyManager / @Dependency |
Supplies the shared manager to intents and queries | CometCal/CometCalApp.swift:16, CometCal/AppIntents/Entities/EventEntity.swift:127 |
| Onscreen entity context | appEntityIdentifier(forSelectionType:) |
Maps visible rows to EventEntity identifiers for Siri |
CometCal/Views/CalendarListView.swift:51 |
| Framework import | CoreSpotlight, GeoToolbox, SwiftData |
Compilation dependencies of the manager | CometCal/Managers/CalendarManager.swift:9 |
| Framework import | AppIntentsTesting |
UI-test target builds intents from IntentDefinitions |
CometCalUITests/Helpers/BaseTestCase.swift:7 |
No Combine publisher scheduling appears in the reviewed files.
Class and protocol design
classDiagram
class EventEntity {
<<AppEntity schema calendar.event>>
}
class EventEntityQuery {
<<EnumerableEntityQuery, EntityStringQuery>>
}
EventEntity *-- EventEntityQuery : defaultQuery
EventEntityQuery --> CalendarManager : @Dependency
CreateEventIntent --> CalendarManager : createEvent
CreateEventIntent --> EventEntity : returns
EventModel --> EventEntity : entity
Reference code
CometCal/AppIntents/Entities/EventEntity.swift:130 — EventEntityQuery
@MainActor
struct EventEntityQuery: EnumerableEntityQuery, EntityStringQuery {
@Dependency
var calendarManager: CalendarManager
func allEntities() async throws -> [EventEntity] {
try calendarManager.fetchEvents().map(\.entity)
}
// ...
}| Type | Responsibility | Depends on |
|---|---|---|
EventEntity, CalendarEntity, AttendeeEntity |
Schema-conforming value snapshots exposed to the system (@AppEntity(schema:)) |
Nested query types |
EventEntityQuery, CalendarEntityQuery |
Resolve identifiers, strings, and suggestions to entities | CalendarManager |
CreateEventIntent, UpdateEventIntent, DeleteEventIntent, OpenEventIntent |
Map schema parameters to manager calls (@AppIntent(schema:)) |
CalendarManager, NavigationManager |
CalendarManager |
SwiftData CRUD, Spotlight indexing, intent donation | ModelContext, CSSearchableIndex, IntentDonationManager |
NavigationManager |
Observable presentation and selection flags | — |
EventModel, CalendarModel, AttendeeModel, ContactModel |
SwiftData persistence | SwiftData relationships |
No local protocol is declared; abstraction comes from framework protocols and schema macros.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
UpdateEventIntent.resolveCalendar() and sibling resolvers |
private |
Only UpdateEventIntent can call the parameter-resolution helpers |
Inference: keep schema-to-model translation inside the intent |
CalendarListView.events, navigation, navigationPath |
private |
View-local query and navigation state | Inference: no other view mutates the path directly |
EventSection |
private (file scope) |
Grouping value usable only in CalendarListView.swift |
Inference: presentation-only helper |
CalendarManager.addAttendee(contact:to:status:) |
private |
Seed-only helper hidden from other files | Inference: keep the seed path separate from the public attendee API |
CalendarManager CRUD methods |
implicit internal |
Callable from views, intents, and test-support intents in the module | Inference: one module-wide data API |
Reference code
CometCal/AppIntents/Intents/UpdateEventIntent.swift:70 — resolveCalendar()
@MainActor
private func resolveCalendar() throws -> CalendarModel? {
guard let calendar else { return nil }
return try calendarManager.fetchCalendars().first(where: { $0.id == calendar.id })
}searchableIndex is nonisolated(unsafe) let, which removes actor-isolation checking rather than restricting visibility (CometCal/Managers/CalendarManager.swift:24).
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Persistence, Spotlight indexing, donation | CalendarManager |
One owner keeps the data store and system index in step for both UI and Siri writes |
| Schema parameter resolution (location, recurrence, attendees) | Each intent, e.g. UpdateEventIntent |
Intents translate system types such as EventLocation into manager arguments |
| Avoiding self-donation | Intents pass donateIntent: false |
System-invoked actions are not donated back; UI-driven calls use the default true (CometCal/AppIntents/Intents/DeleteEventIntent.swift:28) |
| Programmatic navigation | NavigationManager + CalendarListView |
OpenEventIntent sets an ID; the view converts it into a path push (CometCal/AppIntents/Intents/OpenEventIntent.swift:22) |
| Test data reset and seeding | TestSupport/ intents, TestDataHelper |
Debug-only intents let UI tests prepare state through the same intent runtime |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Singleton | CometCal/Managers/CalendarManager.swift:18, CometCal/Managers/NavigationManager.swift:14 |
A shared access point (static let shared) for one data owner and one navigation state. Neither type makes init private (CometCal/Managers/CalendarManager.swift:28 is implicitly internal; NavigationManager has an implicit initializer), so a single instance is a convention, not compiler-enforced. Views reference .shared directly, which couples them to the global |
| App Intents dependency injection | CometCal/CometCalApp.swift:16 and @Dependency in CometCal/AppIntents/Intents/CreateEventIntent.swift:25 |
Intents and queries receive the manager without reaching for the static |
| Observable state owner | CometCal/Managers/NavigationManager.swift:9 observed through CometCal/Views/CalendarListView.swift:16 |
An intent and the UI share one source of presentation truth |
Main application flow
Scope: Siri runs the calendar createEvent schema intent.
sequenceDiagram
participant Runtime as AppIntents
participant Intent as CreateEventIntent
participant Manager as CalendarManager
participant Index as CSSearchableIndex
Runtime->>Intent: perform()
Intent->>Manager: fetchCalendars()
Intent->>Manager: createEvent(donateIntent: false)
Manager->>Manager: insert and save in modelContext
Manager->>Index: Task indexAppEntities
Intent-->>Runtime: result(value: event.entity)
Reference code
CometCal/AppIntents/Intents/CreateEventIntent.swift:33 — perform()
@MainActor
func perform() async throws -> some ReturnsValue<EventEntity> {
// Resolve the calendar, falling back to the first available one.
let calendars = try calendarManager.fetchCalendars()
// ...
let event = try calendarManager.createEvent(
// ...
donateIntent: false
)
return .result(value: event.entity)
}CometCal/Managers/CalendarManager.swift:169 — createEvent
modelContext.insert(event)
try modelContext.save()
// Index the event in Spotlight.
Task {
try? await searchableIndex.indexAppEntities([event.entity])
}Naming conventions
- Types:
<Domain>Modelfor SwiftData classes,<Domain>Entityfor App Intents entities,<Verb><Noun>Intentfor intents,<Domain>EntityQuerynested in its entity,<Role>Managerfor the shared owners. - Protocols: none declared locally.
- Methods: CRUD verbs (
fetchEvents,createEvent,updateEvent,deleteEvent),resolve…for intent parameter translation,open…for navigation commands. - Files and extensions:
CalendarManager+Contacts.swift,+EventUpdates,+SeedDatasplit one type by concern.
Architecture takeaways
- Register one data owner with
AppDependencyManagerand pass the same instance’smodelContainerto the scene, so UI queries observe writes made by Siri. - Keep a thin
entitybridge on each persistence model; intents and queries return value snapshots, not live SwiftData objects. - Put a
donateIntentflag on write methods so UI actions donate but system-invoked intents do not. - Route intent-driven navigation through observable state that the root view turns into a
NavigationPathpush. - Derive the test bundle’s app identifier at run time so
IntentDefinitionslookups survive bundle-ID changes (CometCalUITests/Helpers/BaseTestCase.swift:20).
Source map
| Source file | Relevant symbols |
|---|---|
CometCal/CometCalApp.swift |
CometCalApp, dependency registration |
CometCal/Managers/CalendarManager.swift |
CalendarManager, shared, createEvent, deleteEvent |
CometCal/Managers/CalendarManager+EventUpdates.swift |
applyEventUpdates, donateUpdateIntent |
CometCal/Managers/NavigationManager.swift |
NavigationManager, openEvent |
CometCal/AppIntents/Entities/EventEntity.swift |
EventEntity, EventEntityQuery |
CometCal/AppIntents/Entities/CalendarEntity.swift |
CalendarEntity, CalendarEntityQuery |
CometCal/AppIntents/Intents/CreateEventIntent.swift |
CreateEventIntent.perform() |
CometCal/AppIntents/Intents/UpdateEventIntent.swift |
UpdateEventIntent, resolveCalendar |
CometCal/AppIntents/Intents/DeleteEventIntent.swift |
DeleteEventIntent |
CometCal/AppIntents/Intents/OpenEventIntent.swift |
OpenEventIntent |
CometCal/AppIntents/TestSupport/ResetTestDataIntent.swift |
ResetTestDataIntent |
CometCal/Model/EventModel.swift |
EventModel, entity |
CometCal/Views/CalendarListView.swift |
CalendarListView, EventSection |
CometCal/Views/EditEventView.swift |
calendarManager |
CometCalUITests/Helpers/BaseTestCase.swift |
BaseTestCase, appBundleIdentifier |