Sample CodeiOS, iPadOS, Mac Catalyst, macOSReviewed 2026-07-21View on Apple Developer

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 HoagiePushServerAppContentViewTemplateManagerOrderingServiceCarPlay APIs.
Main patterns Protocol-oriented abstraction, Delegate or data-source callbacks, Service object, Actor-isolated state
Project style 21 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

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

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

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.

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: MemoryLoggerLogger.

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

    private static let apnsTopic = "<Bundle ID>.push-type.liveactivity"
    
    private static let privateKey = """
    Enter Private key as PEM here
    """

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.
Actor-isolated state Hoagies/Hoagies/OrderingService.swift:41 Actor annotations make the concurrency ownership boundary explicit.

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

  • HoagiePushServerApp is 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 HoagiePushServerApp
Hoagies/Hoagies/HoagiesApp.swift HoagiesApp
Hoagies/Hoagies/ContentView.swift ContentView, PickBreadView, PickMeatsView, CheeseView, PickVeggiesView, PickDressingsView, SummaryView
Hoagies/OrderStatus/OrderStatusBundle.swift OrderStatusBundle
Hoagies/Shared/FalseData.swift TestHoagieData, Hoagie, HoagieOrder, func, func, func, HoagieShopMapItem, BaseAddress, CityHall, TheBridge
Hoagies/Hoagies/CarPlay/AppDelegate.swift AppDelegate
Hoagies/Hoagies/CarPlay/TemplateManager.swift TemplateManager, CustomLocalSearchResponse, CustomLocalSearch
Hoagies/Hoagies/OrderingService.swift Order, OrderingError, OrderingService
Hoagies/HoagiePushServer/ContentView.swift ContentView, HoagieServerContentState
Hoagies/Hoagies/CarPlay/CarPlayTemplateApplicationSceneDelegate.swift CarPlayTemplateApplicationSceneDelegate