Integrating your messaging app with Apple Intelligence
At a glance
| Item | Summary |
|---|---|
| Purpose | Adopt message schemas so people can send messages and manage conversations with Siri. |
| App architecture | A Swift sample with the source-visible chain UnicornChatApp → ContactView → ContactManager → AppIntents APIs. |
| Main patterns | Delegate or data-source callbacks, Actor isolation |
| Project style | 47 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: async declaration or closure, @MainActor, Sendable or @Sendable, Mutex, Task; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: @Observable, SwiftUI state property wrapper, NotificationCenter. |
| Key frameworks/packages | SwiftData, SwiftUI, AppIntents, Foundation, PhotosUI; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── UnicornChat/
├── UnicornChatApp.swift
├── Managers/
│ ├── ConversationManager.swift
│ ├── NavigationManager.swift
│ ├── ContactManager.swift
│ ├── GraphicsManager.swift
│ ├── ModelManager.swift
│ └── NotificationManager.swift
├── AppIntents/
│ ├── MessageEntity.swift
│ └── MessageIntents.swift
└── Views/
├── Contact/
│ ├── ContactView.swift
│ └── RecipientsView.swift
└── Conversation/
└── ConversationRowContent.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 4 project/configuration file(s) and 66 source declaration(s).
Overall architecture
flowchart LR
N1["UnicornChatApp"]
N2["ContactView"]
N3["ContactManager"]
N4["AppIntents APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
UnicornChat/UnicornChatApp.swift:12 — architecture anchor
@main
struct UnicornChatApp: App {
// ...
let model: ModelManager
// ...
}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
MessageEntity *-- MessageQuery : defaultQuery
MessageEntity *-- UUID : id
MessageEntity o-- MessageType : messageType
MessageEntity o-- ContactEntity : author
Ownership evidence
UnicornChat/AppIntents/MessageEntity.swift:20 — stored dependency or nearest verified ownership anchor
@AppEntity(schema: .messages.message)
struct MessageEntity: IndexedEntity {
// ...
static let defaultQuery = MessageQuery()
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
MessageEntity |
MessageQuery (defaultQuery) |
creates and retains | Initialized by the owner; the binding is immutable |
MessageEntity |
UUID (id) |
owns value state | App/module collaborators |
MessageEntity |
MessageType (messageType) |
stores or receives | App/module collaborators |
MessageEntity |
ContactEntity (author) |
stores or receives | App/module collaborators |
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 |
|---|---|---|---|
| Suspension boundary | async declaration or closure |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | UnicornChat/AppIntents/ContactEntity.swift:57 |
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | UnicornChat/AppIntents/ConversationIntents.swift:37 |
| Transfer contract | Sendable or @Sendable |
The source declares a sendability boundary; this alone does not synchronize mutable state. | UnicornChat/AppIntents/MessageEntity.swift:165 |
| Synchronization | Mutex |
The source references a synchronization primitive; the protected state requires surrounding review. | UnicornChat/Managers/ConversationManager.swift:59 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | UnicornChat/Managers/ConversationManager.swift:102 |
@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
UnicornChat/AppIntents/ContactEntity.swift:57 — representative execution boundary
func entities(for identifiers: [ContactEntity.ID]) async throws -> [ContactEntity] {
try await model.contactEntities(for: identifiers)
}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. | UnicornChat/Managers/NavigationManager.swift:12 |
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | UnicornChat/Views/Contact/ContactPicker.swift:15 |
| State propagation | NotificationCenter |
NotificationCenter distributes named process-local events. | UnicornChat/Views/Message/MessageList.swift:88 |
| Source import | SwiftData |
The cited file imports this module; runtime use and architectural role are not inferred. | UnicornChat/AppIntents/ConversationIntents.swift:9 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | UnicornChat/Extensions/Color+Extension.swift:8 |
| Source import | AppIntents |
The cited file imports this module; runtime use and architectural role are not inferred. | UnicornChat/AppIntents/AppShortcuts.swift:8 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | UnicornChat/Extensions/Array+Extension.swift:8 |
| Source import | PhotosUI |
The cited file imports this module; runtime use and architectural role are not inferred. | UnicornChat/Extensions/PhotosItem+Extension.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
UnicornChat/UnicornChatApp.swift:13 — representative type boundary
@main
struct UnicornChatApp: App {
// ...
let model: ModelManager
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
UnicornChatApp |
Application entry and top-level composition | App |
ConversationManager |
Long-lived feature or framework coordination | Sendable |
NavigationManager |
Long-lived feature or framework coordination | Concrete collaborators/imported frameworks |
ConversationModel |
Feature data or observable state | Concrete collaborators/imported frameworks |
ContactManager |
Long-lived feature or framework coordination | Concrete collaborators/imported frameworks |
GraphicsManager |
Long-lived feature or framework coordination | Sendable |
ModelManager |
Long-lived feature or framework coordination | Concrete collaborators/imported frameworks |
NotificationManager |
Long-lived feature or framework coordination | NSObject |
ContactView |
User-interface presentation and input forwarding | View |
RecipientsView |
User-interface presentation and input forwarding | View |
No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
ContactManager (UnicornChat/Managers/ContactManager.swift:69) |
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. |
model (UnicornChat/Managers/ConversationManager.swift:54) |
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. |
sessions (UnicornChat/Managers/ConversationManager.swift:59) |
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. |
generateResponse (UnicornChat/Managers/ConversationManager.swift:138) |
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. |
Reference code
UnicornChat/Managers/ContactManager.swift:69 — representative boundary
private init() {}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 | UnicornChatApp |
The source’s App suffix makes this role explicit. |
| Long-lived feature or framework coordination | ContactManager, ConversationManager, GraphicsManager, ModelManager |
The source’s Manager suffix makes this role explicit. |
| Feature data or observable state | ConversationModel |
The source’s Model suffix makes this role explicit. |
| User-interface presentation and input forwarding | ContactView, ContentView, ConversationView, CreateMessageView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Delegate or data-source callbacks | UnicornChat/Managers/NotificationManager.swift:139 |
Callback protocols invert event delivery back into the sample’s owner. |
| Actor isolation | UnicornChat/Managers/ModelManager.swift:14 |
A declared actor creates an explicit isolation boundary; its executor is not described as a background thread. |
Main application flow
sequenceDiagram
participant ModelManager
participant CSSearchableIndex
participant NotificationManager
ModelManager->>CSSearchableIndex: default()
ModelManager->>CSSearchableIndex: default()
ModelManager->>CSSearchableIndex: default()
ModelManager->>NotificationManager: requestAuthorization()
Reference code
UnicornChat/Managers/ModelManager.swift:77 — storeDidFinishLaunching()
func storeDidFinishLaunching() async throws {
let contacts = ContactManager.shared.contacts
// Stage permanent data.
for contact in contacts {
modelContext.insert(contact)
}
try modelContext.save()
// Fetch entities.
let contactEntities = try fetchRecentContacts(limit: nil).map(\.entity)
let conversationEntities = try fetchRecentConversations(limit: nil).map(\.entity)
let messageEntities = try fetchRecentMessages(limit: nil).map(\.entity)
// Index content to Spotlight.
try? await CSSearchableIndex.default().indexAppEntities(contactEntities)
try? await CSSearchableIndex.default().indexAppEntities(conversationEntities)
try? await CSSearchableIndex.default().indexAppEntities(messageEntities)
// Request permission to post notifications at launch.
try await NotificationManager.shared.requestAuthorization()
}Naming conventions
- Types: App: UnicornChatApp; Manager: ContactManager, ConversationManager, GraphicsManager, ModelManager, NavigationManager; Model: ConversationModel; View: ContactView, ContentView, ConversationView, CreateMessageView, RecipientsView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
responses,generateResponse,session,instructions,buildPrompt,entities,suggestedEntities,perform. - Files:
UnicornChat/UnicornChatApp.swift,UnicornChat/Managers/ConversationManager.swift,UnicornChat/AppIntents/MessageEntity.swift,UnicornChat/Managers/NavigationManager.swift,UnicornChat/Managers/ContactManager.swift,UnicornChat/Managers/GraphicsManager.swift.
Architecture takeaways
UnicornChatAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftData, SwiftUI, AppIntents, PhotosUI 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.
- The source does not justify labeling the design protocol-oriented.
Source map
| Source file | Relevant symbols |
|---|---|
UnicornChat/UnicornChatApp.swift |
Cited implementation, UnicornChatApp |
UnicornChat/AppIntents/MessageEntity.swift |
Cited implementation, Sendable or @Sendable, MessageEntity, CustomAttachment, CustomAttachmentQuery, MessageType, MessageAttribute, MessageEffect, MessageReaction, CustomReaction, MessageQuery |
UnicornChat/Managers/ContactManager.swift |
Cited implementation, ContactManager |
UnicornChat/Managers/ConversationManager.swift |
Cited implementation, Mutex, Task, ConversationManager, MessageSnapshot, RecipientSnapshot, GeneratedResponse, Error |
UnicornChat/Managers/NotificationManager.swift |
Cited implementation, NotificationManager |
UnicornChat/Managers/ModelManager.swift |
ModelManager |
UnicornChat/AppIntents/ContactEntity.swift |
async declaration or closure, ContactEntity, UnicornQuery |
UnicornChat/AppIntents/ConversationIntents.swift |
@MainActor, SwiftData, ConversationIntentError, OpenConversationIntent |
UnicornChat/Managers/NavigationManager.swift |
@Observable, NavigationManager, ConversationModel |
UnicornChat/Views/Contact/ContactPicker.swift |
SwiftUI state property wrapper, ContactPicker, Row |
UnicornChat/Views/Message/MessageList.swift |
NotificationCenter, MessageList |
UnicornChat/Extensions/Color+Extension.swift |
SwiftUI, Feature implementation |
UnicornChat/AppIntents/AppShortcuts.swift |
AppIntents, AppShortcuts |
UnicornChat/Extensions/Array+Extension.swift |
Foundation, Feature implementation |
UnicornChat/Extensions/PhotosItem+Extension.swift |
PhotosUI, Feature implementation |
UnicornChat/AppIntents/MessageIntents.swift |
MessageDestination, SendMessageIntent, DraftMessageIntent, SetMessageReadStatusIntent, EditSentMessageIntent, UnsendMessageIntent |