Integrating CarPlay with your quick-ordering app
At a glance
| Item | Summary |
|---|---|
| Purpose | Configure your food-ordering app to work with CarPlay. |
| App architecture | A Swift sample with the source-visible chain HoagiePushServerApp → ContentView → TemplateManager → OrderingService → CarPlay APIs. |
| Main patterns | Protocol-oriented abstraction, Delegate or data-source callbacks, Service object |
| Project style | 21 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: async declaration or closure, Task, DispatchQueue.main.async, @MainActor, Task closure isolated to MainActor; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: SwiftUI state property wrapper, @Observable, ObservableObject. |
| Key frameworks/packages | SwiftUI, WidgetKit, ActivityKit, CarPlay, Foundation; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── Hoagies/
├── HoagiePushServer/
│ ├── HoagiePushServerApp.swift
│ └── ContentView.swift
├── Hoagies/
│ ├── HoagiesApp.swift
│ ├── ContentView.swift
│ ├── CarPlay/
│ │ ├── AppDelegate.swift
│ │ ├── TemplateManager.swift
│ │ ├── CarPlayTemplateApplicationSceneDelegate.swift
│ │ └── SceneDelegate.swift
│ └── OrderingService.swift
├── OrderStatus/
│ ├── OrderStatusBundle.swift
│ └── OrderStatus.swift
└── Shared/
└── FalseData.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 44 source declaration(s).
Overall architecture
flowchart LR
N1["HoagiePushServerApp"]
N2["ContentView"]
N3["TemplateManager"]
N4["OrderingService"]
N5["CarPlay APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
Hoagies/HoagiePushServer/HoagiePushServerApp.swift:9 — architecture anchor
@main
struct HoagiePushServerApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}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 CarPlay.
Ownership and state
classDiagram
ContentView o-- MemoryLogger : shared
PickBreadView *-- Hoagie : hoagie
PickMeatsView *-- Hoagie : hoagie
CheeseView *-- Hoagie : hoagie
Ownership evidence
Hoagies/Hoagies/ContentView.swift:12 — stored dependency or nearest verified ownership anchor
struct ContentView: View {
// ...
@Bindable var shared: MemoryLogger
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
ContentView |
MemoryLogger (shared) |
stores or receives | App/module collaborators |
PickBreadView |
Hoagie (hoagie) |
owns wrapper-managed state | App/module collaborators |
PickMeatsView |
Hoagie (hoagie) |
owns wrapper-managed state | App/module collaborators |
CheeseView |
Hoagie (hoagie) |
owns wrapper-managed state | 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. | Hoagies/HoagiePushServer/APNS.swift:122 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | Hoagies/HoagiePushServer/ContentView.swift:35 |
| Queue scheduling | DispatchQueue.main.async |
The source addresses the main dispatch queue. | Hoagies/Hoagies/CarPlay/Logger.swift:50 |
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | Hoagies/Hoagies/OrderingService.swift:100 |
| Main isolation | Task closure isolated to MainActor |
The cited operation explicitly enters a main-actor-isolated region. | Hoagies/Hoagies/OrderingService.swift:100 |
@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
Hoagies/HoagiePushServer/APNS.swift:122 — representative execution boundary
static func sendLiveActivityContent(
// ...
order: TestHoagieData.HoagieOrder? = nil) async throws {
// ...
}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 | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | Hoagies/HoagiePushServer/ContentView.swift:12 |
| State propagation | @Observable |
Observation macro publishes source-visible changes. | Hoagies/Hoagies/CarPlay/Logger.swift:32 |
| State propagation | ObservableObject |
ObservableObject supplies an observation contract. | Hoagies/Hoagies/OrderingService.swift:21 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | Hoagies/HoagiePushServer/ContentView.swift:8 |
| Source import | WidgetKit |
The cited file imports this module; runtime use and architectural role are not inferred. | Hoagies/Hoagies/OrderingService.swift:9 |
| Source import | ActivityKit |
The cited file imports this module; runtime use and architectural role are not inferred. | Hoagies/Hoagies/OrderingService.swift:8 |
| Source import | CarPlay |
The cited file imports this module; runtime use and architectural role are not inferred. | Hoagies/Hoagies/CarPlay/CarPlayTemplateApplicationSceneDelegate.swift:8 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | Hoagies/HoagiePushServer/APNS.swift:8 |
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
Hoagies/Hoagies/CarPlay/Logger.swift:21 — representative type boundary
protocol Logger {
/// Append a new event to the log. The system adds all events at the 0 index.
func appendEvent(_: String)
/// Fetch the list of events that this logger receives.
var events: [Event] { get }
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
HoagiePushServerApp |
Application entry and top-level composition | App |
HoagiesApp |
Application entry and top-level composition | App |
ContentView |
User-interface presentation and input forwarding | View |
PickBreadView |
User-interface presentation and input forwarding | View |
PickMeatsView |
User-interface presentation and input forwarding | View |
CheeseView |
User-interface presentation and input forwarding | View |
PickVeggiesView |
User-interface presentation and input forwarding | View |
PickDressingsView |
User-interface presentation and input forwarding | View |
SummaryView |
User-interface presentation and input forwarding | View |
AppDelegate |
Receives callback-driven events | NSObject, UIApplicationDelegate |
The source explicitly defines local protocol relationships: MemoryLogger → Logger.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
apnsTopic (Hoagies/HoagiePushServer/APNS.swift:23) |
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. |
privateKey (Hoagies/HoagiePushServer/APNS.swift:25) |
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. |
keyIdentifier (Hoagies/HoagiePushServer/APNS.swift:29) |
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. |
teamIdentifier (Hoagies/HoagiePushServer/APNS.swift:30) |
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
Hoagies/HoagiePushServer/APNS.swift:23 — representative boundary
final class APNS {
// ...
private static let apnsTopic = "<Bundle ID>.push-type.liveactivity"
// ...
}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 | HoagiePushServerApp, HoagiesApp |
The source’s App suffix makes this role explicit. |
| Receives callback-driven events | AppDelegate, CarPlayTemplateApplicationSceneDelegate, SceneDelegate |
The source’s Delegate suffix makes this role explicit. |
| Long-lived feature or framework coordination | TemplateManager |
The source’s Manager suffix makes this role explicit. |
| Supplies a capability or framework resource | Provider |
The source’s Provider suffix makes this role explicit. |
| Framework-facing operations | OrderingService |
The source’s Service suffix makes this role explicit. |
| User-interface presentation and input forwarding | CheeseView, ContentView, OrderStatusEntryView, OrderStatusView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Protocol-oriented abstraction | Hoagies/Hoagies/CarPlay/Logger.swift:32 |
A local protocol and concrete conformance create an explicit capability boundary. |
| Delegate or data-source callbacks | Hoagies/Hoagies/CarPlay/AppDelegate.swift:10 |
Callback protocols invert event delivery back into the sample’s owner. |
| Service object | Hoagies/Hoagies/OrderingService.swift:21 |
A role-named service contains framework-facing operations. |
Naming conventions
- Types: App: HoagiePushServerApp, HoagiesApp; Delegate: AppDelegate, CarPlayTemplateApplicationSceneDelegate, SceneDelegate; Manager: TemplateManager; Provider: Provider; Service: OrderingService; View: CheeseView, ContentView, OrderStatusEntryView, OrderStatusView, PickBreadView.
- Protocols:
Logger. - Methods:
saveLastOrder,houseFavoriteOrder,lastOrder,testMapItems,application,applicationDidBecomeActive,applicationWillResignActive,applicationDidEnterBackground. - Files:
Hoagies/HoagiePushServer/HoagiePushServerApp.swift,Hoagies/Hoagies/HoagiesApp.swift,Hoagies/Hoagies/ContentView.swift,Hoagies/OrderStatus/OrderStatusBundle.swift,Hoagies/Hoagies/CarPlay/AppDelegate.swift,Hoagies/Hoagies/CarPlay/TemplateManager.swift.
Architecture takeaways
HoagiePushServerAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, WidgetKit, ActivityKit, CarPlay 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 |
|---|---|
Hoagies/HoagiePushServer/HoagiePushServerApp.swift |
Cited implementation, HoagiePushServerApp |
Hoagies/Hoagies/ContentView.swift |
Cited implementation, ContentView, PickBreadView, PickMeatsView, CheeseView, PickVeggiesView, PickDressingsView, SummaryView |
Hoagies/Hoagies/CarPlay/Logger.swift |
Logger, Cited implementation, DispatchQueue.main.async, @Observable, Event, MemoryLogger |
Hoagies/HoagiePushServer/APNS.swift |
Cited implementation, async declaration or closure, Foundation, APNS, Header, Payload |
Hoagies/Hoagies/CarPlay/AppDelegate.swift |
Cited implementation, AppDelegate |
Hoagies/Hoagies/OrderingService.swift |
OrderingService, @MainActor, Task closure isolated to MainActor, ObservableObject, WidgetKit, ActivityKit, Order, OrderingError |
Hoagies/HoagiePushServer/ContentView.swift |
Task, SwiftUI state property wrapper, SwiftUI, ContentView, HoagieServerContentState |
Hoagies/Hoagies/CarPlay/CarPlayTemplateApplicationSceneDelegate.swift |
CarPlay, CarPlayTemplateApplicationSceneDelegate |
Hoagies/Hoagies/HoagiesApp.swift |
HoagiesApp |
Hoagies/OrderStatus/OrderStatusBundle.swift |
OrderStatusBundle |
Hoagies/Shared/FalseData.swift |
TestHoagieData, Hoagie, HoagieOrder, func, HoagieShopMapItem, BaseAddress, CityHall, TheBridge |
Hoagies/Hoagies/CarPlay/TemplateManager.swift |
TemplateManager, CustomLocalSearchResponse, CustomLocalSearch |
Hoagies/Hoagies/CarPlay/SceneDelegate.swift |
SceneDelegate |
Hoagies/OrderStatus/OrderStatus.swift |
Provider, HoagieOrderEntry, OrderStatusEntryView, OrderStatus |
Hoagies/Shared/OrderStatusView.swift |
OrderStatusView |
Hoagies/Shared/ActivityAttributes.swift |
OrderStatusAttributes, ContentStateValues, ContentState |