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

Food Truck: Building a SwiftUI multiplatform app

At a glance

Item Summary
Purpose Create a single codebase and app target for Mac, iPad, and iPhone.
App architecture A Swift sample bundle with entry-bearing project variants App, Widgets, each leading to SwiftUI APIs.
Main patterns View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks, Central store, SwiftUI environment injection, Binding-based state propagation
Project style 82 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
├── App/
│   ├── App.swift
│   ├── Store/
│   │   ├── SubscriptionStoreView.swift
│   │   └── UnlockFeatureView.swift
│   ├── Account/
│   │   └── SignUpView.swift
│   └── Truck/
│       └── TruckView.swift
├── Widgets/
│   └── Widgets.swift
└── FoodTruckKit/
    └── Sources/
        ├── Donut/
        │   ├── DonutBoxView.swift
        │   └── DonutView.swift
        ├── Model/
        │   └── FoodTruckModel.swift
        ├── Order/
        │   └── OrderGenerator.swift
        ├── Store/
        │   └── StoreMessagesManager.swift
        └── Account/
            └── AccountStore.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 11 project/configuration file(s) and 160 source declaration(s).

Overall architecture

Reference code

App/App.swift:15 — architecture anchor

@main
struct FoodTruckApp: App {
    // ...
}

Interpretation

The branches represent separate entry-bearing project variants in the downloaded bundle, not runtime calls between those variants. Each branch is intentionally collapsed at the documented framework boundary; the detailed target-local flow remains in the cited files. Ownership is claimed only where the next section cites a stored property or assignment.

Ownership and state

Ownership evidence

App/App.swift:18 — stored dependency or nearest verified ownership anchor

@main
struct FoodTruckApp: App {
    // ...
    @StateObject private var model = FoodTruckModel()
    // ...
}
Owner Object or state Relationship Mutation authority
FoodTruckApp FoodTruckModel (model) owns wrapper-managed state Owning lexical scope
FoodTruckApp AccountStore (accountStore) owns wrapper-managed state Owning lexical scope
SignUpView FoodTruckModel (model) observes externally owned state The observed object is authoritative
SignUpView AccountStore (accountStore) receives environment-provided state The environment provider is authoritative

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

FoodTruckKit/Sources/Donut/Ingredients/Ingredient.swift:10 — representative type boundary

public protocol Ingredient: Identifiable, Hashable {
    var id: String { get }
    var name: String { get }
    var flavors: FlavorProfile { get }
    var imageAssetName: String { get }
    static var imageAssetPrefix: String { get }
}
Type Responsibility Depends on or conforms to
FoodTruckApp Application entry and top-level composition App
SubscriptionStoreView User-interface presentation and input forwarding View
SubscriptionStoreHeaderView User-interface presentation and input forwarding View
SubscriptionStoreOptionsView User-interface presentation and input forwarding View
SubscriptionOptionView User-interface presentation and input forwarding View
SubscriptionPurchaseView User-interface presentation and input forwarding View
SignUpView User-interface presentation and input forwarding View
DonutBoxView User-interface presentation and input forwarding Concrete collaborators/imported frameworks
DonutView User-interface presentation and input forwarding View
FoodTruckModel Feature data or observable state ObservableObject

The source explicitly defines local protocol relationships: DoughIngredient, GlazeIngredient, ToppingIngredient.

Access control

Symbol Access Verified effect Likely rationale
accountStore (App/Account/AccountView.swift:16) 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.
authorizationController (App/Account/AccountView.swift:17) 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.
isSignUpSheetPresented (App/Account/AccountView.swift:19) 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.
isSignOutAlertPresented (App/Account/AccountView.swift:20) 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

App/Account/AccountView.swift:16 — representative boundary

    @EnvironmentObject private var accountStore: AccountStore
    @Environment(\.authorizationController) private var authorizationController
    
    @State private var isSignUpSheetPresented = false
    @State private var isSignOutAlertPresented = false

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 FoodTruckApp The source’s App suffix makes this role explicit.
View lifecycle, callbacks, and feature coordination Controller, StoreProductController, StoreSubscriptionController The source’s Controller suffix makes this role explicit.
Generates feature data or resources OrderGenerator, SeededRandomGenerator The source’s Generator suffix makes this role explicit.
Long-lived feature or framework coordination StoreMessagesManager The source’s Manager suffix makes this role explicit.
Feature data or observable state FoodTruckModel The source’s Model suffix makes this role explicit.
Supplies a capability or framework resource Provider, TruckActivityPreviewProvider The source’s Provider suffix makes this role explicit.
Owns drawing, GPU, or presentation processing DonutRenderer The source’s Renderer suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization App/City/DetailedMapView.swift:30 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Protocol-oriented abstraction FoodTruckKit/Sources/Donut/Ingredients/Dough.swift:11 A local protocol and concrete conformance create an explicit capability boundary.
Delegate or data-source callbacks FoodTruckKit/Sources/Account/AccountStore.swift:38 Callback protocols invert event delivery back into the sample’s owner.
Central store FoodTruckKit/Sources/Account/AccountStore.swift:38 A store-named type centralizes feature state or persistence.
SwiftUI environment injection App/Account/AccountView.swift:16 The environment supplies state or a capability without threading it through every initializer.
Binding-based state propagation App/Donut/DonutEditor.swift:12 A binding exposes controlled read/write access while the upstream owner remains authoritative.

Naming conventions

  • Types: App: FoodTruckApp; Controller: Controller, StoreProductController, StoreSubscriptionController; Generator: OrderGenerator, SeededRandomGenerator; Manager: StoreMessagesManager; Model: FoodTruckModel; Provider: Provider, TruckActivityPreviewProvider; Renderer: DonutRenderer; Store: AccountStore.
  • Protocols: Ingredient.
  • Methods: binding, subscriptionOptionCell, savings, applyKerning, signUp, dailyOrderSummaries, monthlyOrderSummaries, donuts.
  • Files: App/Store/SubscriptionStoreView.swift, Widgets/Widgets.swift, App/Account/SignUpView.swift, FoodTruckKit/Sources/Donut/DonutBoxView.swift, FoodTruckKit/Sources/Donut/DonutView.swift, FoodTruckKit/Sources/Model/FoodTruckModel.swift.

Architecture takeaways

  • App is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SwiftUI, FoodTruckKit, StoreKit, WidgetKit 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
App/App.swift FoodTruckApp
App/Store/SubscriptionStoreView.swift SubscriptionStoreView, SubscriptionStoreHeaderView, SubscriptionStoreOptionsView, SubscriptionOptionView, SubscriptionPurchaseView, SubscriptionStoreView_Previews
Widgets/Widgets.swift Widgets
App/Account/SignUpView.swift SignUpView, FocusElement, SignUpType, SignUpView_Previews, Preview
FoodTruckKit/Sources/Donut/DonutBoxView.swift DonutBoxView, DonutBoxView_Previews, Preview
FoodTruckKit/Sources/Donut/DonutView.swift DonutView, DonutLayer, DonutCanvas_Previews
FoodTruckKit/Sources/Model/FoodTruckModel.swift FoodTruckModel, DonutSortOrder, Timeframe
FoodTruckKit/Sources/Order/OrderGenerator.swift OrderGenerator, RandomInfo, SeededRandomGenerator
FoodTruckKit/Sources/Store/StoreMessagesManager.swift StoreMessagesManager, StoreMessagesDeferredPreferenceKey, StoreMessagesDeferredModifier
App/Store/UnlockFeatureView.swift UnlockFeatureView, UnlockFeatureExpandedView, UnlockFeatureSimpleView, UnlockFeatureView_Previews