Accelerating app interactions with App Intents
At a glance
| Item | Summary |
|---|---|
| Purpose | Enable people to use your app’s features quickly through Siri, Spotlight, and Shortcuts. |
| App architecture | A Swift sample with the source-visible chain AppIntentsSampleApp → ContentView → AccountManager → LocationOptionsProvider → AppIntents APIs. |
| Main patterns | Protocol-oriented abstraction |
| Project style | 40 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: @MainActor, async declaration or closure, Task, Sendable or @Sendable, Task closure isolated to MainActor; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: @Observable, SwiftUI state property wrapper. |
| Key frameworks/packages | Foundation, AppIntents, SwiftUI, OSLog, Observation; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── AppIntentsSampleApp/
├── AppIntentsSampleApp.swift
├── Model/
│ ├── ActivityTracker.swift
│ ├── TrailCollection.swift
│ ├── AccountManager.swift
│ ├── NavigationModel.swift
│ └── TrailDataManager.swift
├── App Intents/
│ ├── Entities/
│ │ └── LocationOptionsProvider.swift
│ └── OpenTrail.swift
└── Views/
├── ActiveActivityInfoView.swift
├── ContentView.swift
├── TrailDetailView.swift
└── TrailInfoView.swift
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: Swift.
- The verified tree contains 8 project/configuration file(s) and 42 source declaration(s).
Overall architecture
flowchart LR
N1["AppIntentsSampleApp"]
N2["ContentView"]
N3["AccountManager"]
N4["LocationOptionsProvider"]
N5["AppIntents APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
AppIntentsSampleApp/AppIntentsSampleApp.swift:11 — architecture anchor
@main
struct AppIntentsSampleApp: App {
// ...
private var trailManager: TrailDataManager
// ...
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into App Intents.
Ownership and state
classDiagram
AppIntentsSampleApp o-- TrailDataManager : trailManager
AppIntentsSampleApp o-- NavigationModel : sceneNavigationModel
AppIntentsSampleApp o-- AccountManager : accountManager
AppIntentsSampleApp o-- ActivityTracker : activityManager
Ownership evidence
AppIntentsSampleApp/AppIntentsSampleApp.swift:14 — stored dependency or nearest verified ownership anchor
@main
struct AppIntentsSampleApp: App {
// ...
private var trailManager: TrailDataManager
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
AppIntentsSampleApp |
TrailDataManager (trailManager) |
stores or receives | Owning lexical scope |
AppIntentsSampleApp |
NavigationModel (sceneNavigationModel) |
stores or receives | Initialized by the owner; the binding is immutable |
AppIntentsSampleApp |
AccountManager (accountManager) |
stores or receives | Owning lexical scope |
AppIntentsSampleApp |
ActivityTracker (activityManager) |
stores or receives | Owning lexical scope |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
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 isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | AppIntentsSampleApp/App Intents/BuyDayPass.swift:16 |
| Suspension boundary | async declaration or closure |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | AppIntentsSampleApp/App Intents/BuyDayPass.swift:17 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | AppIntentsSampleApp/App Intents/Workout Intents/StartTrailActivity.swift:79 |
| Transfer contract | Sendable or @Sendable |
The source declares a sendability boundary; this alone does not synchronize mutable state. | AppIntentsSampleApp/Model/AccountManager.swift:12 |
| Main isolation | Task closure isolated to MainActor |
The cited operation explicitly enters a main-actor-isolated region. | AppIntentsSampleApp/Views/ActiveActivityInfoView.swift:45 |
@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.
Reference code
AppIntentsSampleApp/App Intents/BuyDayPass.swift:16 — representative execution boundary
@MainActor
func perform() async throws -> some IntentResult & ProvidesDialog {
// ...
let passAmount = IntentCurrencyAmount(amount: 6.50, currencyCode: "USD")
// ...
}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 | @Observable |
Observation macro publishes source-visible changes. | AppIntentsSampleApp/Model/AccountManager.swift:12 |
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | AppIntentsSampleApp/Views/ActiveActivityInfoView.swift:11 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | AppIntentsSampleApp/App Intents/BuyDayPass.swift:9 |
| Source import | AppIntents |
The cited file imports this module; runtime use and architectural role are not inferred. | AppIntentsSampleApp/App Intents/BuyDayPass.swift:8 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | AppIntentsSampleApp/AppIntentsSampleApp.swift:9 |
| Source import | OSLog |
The cited file imports this module; runtime use and architectural role are not inferred. | AppIntentsSampleApp/App Intents/BuyDayPass.swift:10 |
| Source import | Observation |
The cited file imports this module; runtime use and architectural role are not inferred. | AppIntentsSampleApp/Model/AccountManager.swift:9 |
| Source import | CoreLocation |
The cited file imports this module; runtime use and architectural role are not inferred. | AppIntentsSampleApp/Model/Trail.swift:9 |
receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.
Class and protocol design
AppIntentsSampleApp/Model/ActivityTracker.swift:257 — representative type boundary
@MainActor
private protocol ActivityTrackingActions {
var isActivityTrackingAuthorized: Bool { get }
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
AppIntentsSampleApp |
Application entry and top-level composition | App |
ActivityTracker |
Owns tracking state and updates | ActivityTrackingActions, @unchecked Sendable |
LiveWorkoutManager |
Long-lived feature or framework coordination | NSObject, ActivityTrackingActions |
LocationOptionsProvider |
Supplies a capability or framework resource | DynamicOptionsProvider |
AccountManager |
Long-lived feature or framework coordination | @unchecked Sendable |
NavigationModel |
Feature data or observable state | Concrete collaborators/imported frameworks |
TrailDataManager |
Long-lived feature or framework coordination | @unchecked Sendable |
ActiveActivityInfoView |
User-interface presentation and input forwarding | View |
ContentView |
User-interface presentation and input forwarding | View |
TrailDetailView |
User-interface presentation and input forwarding | View |
The source explicitly defines local protocol relationships: ActivityTracker → ActivityTrackingActions, LiveWorkoutManager → ActivityTrackingActions.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
formattedSummary (AppIntentsSampleApp/App Intents/Entities/ActivityStatisticsSummary+Transferable.swift:35) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
richTextRepresentation (AppIntentsSampleApp/App Intents/Entities/ActivityStatisticsSummary+Transferable.swift:57) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
textToImage (AppIntentsSampleApp/App Intents/Entities/ActivityStatisticsSummary+Transferable.swift:71) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: hide an implementation step that is not part of the collaboration surface. |
imageFileRepresentation (AppIntentsSampleApp/App Intents/Entities/ActivityStatisticsSummary+Transferable.swift:89) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
Reference code
AppIntentsSampleApp/App Intents/Entities/ActivityStatisticsSummary+Transferable.swift:35 — representative boundary
#if canImport(UIKIt)
private var formattedSummary: AttributedString {
let distanceStyle = Measurement<UnitLength>.FormatStyle(width: .abbreviated, usage: .road)
// ...
}
#endif // canImport(UIKit)Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Application entry and top-level composition | AppIntentsSampleApp |
The source’s App suffix makes this role explicit. |
| Long-lived feature or framework coordination | AccountManager, LiveWorkoutManager, TrailDataManager |
The source’s Manager suffix makes this role explicit. |
| Feature data or observable state | NavigationModel |
The source’s Model suffix makes this role explicit. |
| Supplies a capability or framework resource | LocationOptionsProvider |
The source’s Provider suffix makes this role explicit. |
| Owns tracking state and updates | ActivityTracker |
The source’s Tracker suffix makes this role explicit. |
| User-interface presentation and input forwarding | ActiveActivityInfoView, ContentView, TrailDetailView, TrailInfoView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Protocol-oriented abstraction | AppIntentsSampleApp/Model/ActivityTracker.swift:15 |
A local protocol and concrete conformance create an explicit capability boundary. |
Naming conventions
- Types: App: AppIntentsSampleApp; Manager: AccountManager, LiveWorkoutManager, TrailDataManager; Model: NavigationModel; Provider: LocationOptionsProvider; Tracker: ActivityTracker; View: ActiveActivityInfoView, ContentView, TrailDetailView, TrailInfoView.
- Protocols:
ActivityTrackingActions. - Methods:
requestActivityTrackingAuthorization,startNewActivity,pauseActivity,resumeActivity,endActivity,activityHistory,saveHistory,hash. - Files:
AppIntentsSampleApp/AppIntentsSampleApp.swift,AppIntentsSampleApp/Model/ActivityTracker.swift,AppIntentsSampleApp/Model/TrailCollection.swift,AppIntentsSampleApp/App Intents/Entities/LocationOptionsProvider.swift,AppIntentsSampleApp/Model/AccountManager.swift,AppIntentsSampleApp/Model/NavigationModel.swift.
Architecture takeaways
AppIntentsSampleAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches AppIntents, SwiftUI, CoreLocation, HealthKit through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- Local protocol relationships provide an explicit substitution boundary.
Source map
| Source file | Relevant symbols |
|---|---|
AppIntentsSampleApp/AppIntentsSampleApp.swift |
Cited implementation, SwiftUI, AppIntentsSampleApp |
AppIntentsSampleApp/Model/ActivityTracker.swift |
ActivityTrackingActions, Cited implementation, ActivityTracker, LiveWorkoutManager |
AppIntentsSampleApp/App Intents/Entities/ActivityStatisticsSummary+Transferable.swift |
Cited implementation, Feature implementation |
AppIntentsSampleApp/App Intents/BuyDayPass.swift |
@MainActor, async declaration or closure, Foundation, AppIntents, OSLog, BuyDayPass |
AppIntentsSampleApp/App Intents/Workout Intents/StartTrailActivity.swift |
Task, StartTrailActivity |
AppIntentsSampleApp/Model/AccountManager.swift |
Sendable or @Sendable, @Observable, Observation, AccountManager |
AppIntentsSampleApp/Views/ActiveActivityInfoView.swift |
Task closure isolated to MainActor, SwiftUI state property wrapper, ActiveActivityInfoView |
AppIntentsSampleApp/Model/Trail.swift |
CoreLocation, Trail, TrailData, DataContainer |
AppIntentsSampleApp/Model/TrailCollection.swift |
TrailCollection, CollectionType, CodingKeys |
AppIntentsSampleApp/App Intents/Entities/LocationOptionsProvider.swift |
LocationOptionsProvider |
AppIntentsSampleApp/Model/NavigationModel.swift |
NavigationModel |
AppIntentsSampleApp/Model/TrailDataManager.swift |
TrailDataManager |
AppIntentsSampleApp/Views/ContentView.swift |
ContentView |
AppIntentsSampleApp/Views/TrailDetailView.swift |
TrailDetailView |
AppIntentsSampleApp/Views/TrailInfoView.swift |
TrailInfoView |
AppIntentsSampleApp/App Intents/OpenTrail.swift |
OpenTrail |