Bringing robust navigation structure to your SwiftUI app
At a glance
| Item | Summary |
|---|---|
| Purpose | Use navigation links, stacks, destinations, and paths to provide a streamlined experience for all platforms, as well as behaviors such as deep linking and state restoration. |
| App architecture | A Swift sample with the source-visible chain NavigationCookbookApp → ContentView → DataModel → SwiftUI APIs. |
| Main patterns | Binding-based state propagation |
| Project style | 21 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | No structured execution marker indexed; callback threading requires source review. |
| State/event model | Source-visible mechanisms: @Observable, SwiftUI state property wrapper. |
| Key frameworks/packages | SwiftUI, Combine; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── NavigationCookbook/
├── NavigationCookbookApp.swift
├── Models/
│ ├── NavigationModel.swift
│ ├── DataModel.swift
│ ├── Recipe.swift
│ ├── Category.swift
│ ├── Experience.swift
│ └── Ingredient.swift
└── Views/
├── ContentView.swift
├── StackContentView.swift
├── ThreeColumnContentView.swift
├── TwoColumnContentView.swift
└── ContinueButton.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 24 source declaration(s).
Overall architecture
flowchart LR
N1["NavigationCookbookApp"]
N2["ContentView"]
N3["DataModel"]
N4["SwiftUI APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
NavigationCookbook/NavigationCookbookApp.swift:11 — architecture anchor
@main
struct NavigationCookbookApp: App {
var body: some Scene {
WindowGroup {
ContentView()
#if os(macOS)
.frame(minWidth: 800, minHeight: 600)
#endif
}
#if os(macOS)
.commands {
SidebarCommands()
}
#endif
}
}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 SwiftUI.
Ownership and state
classDiagram
NavigationModel o-- Category : selectedCategory
NavigationModel *-- Array : recipePath
NavigationModel o-- NavigationSplitViewVisibility : columnVisibility
NavigationModel *-- JSONDecoder : decoder
Ownership evidence
NavigationCookbook/Models/NavigationModel.swift:16 — stored dependency or nearest verified ownership anchor
@Observable
final class NavigationModel: Codable {
// ...
var selectedCategory: Category?
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
NavigationModel |
Category (selectedCategory) |
stores or receives | App/module collaborators |
NavigationModel |
Array (recipePath) |
owns value state | App/module collaborators |
NavigationModel |
NavigationSplitViewVisibility (columnVisibility) |
stores or receives | App/module collaborators |
NavigationModel |
JSONDecoder (decoder) |
creates and retains | Initialized by the owner; the binding is immutable |
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.
No source-visible execution, scheduling, or synchronization boundary was found in the indexed source.
@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.
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. | NavigationCookbook/Models/DataModel.swift:11 |
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | NavigationCookbook/Views/ContentView.swift:12 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | NavigationCookbook/Models/Category.swift:9 |
| Source import | Combine |
The cited file imports this module; runtime use and architectural role are not inferred. | NavigationCookbook/Models/NavigationModel.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
NavigationCookbook/NavigationCookbookApp.swift:12 — representative type boundary
@main
struct NavigationCookbookApp: App {
// ...
ContentView()
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
NavigationCookbookApp |
Application entry and top-level composition | App |
NavigationModel |
Feature data or observable state | Codable |
DataModel |
Feature data or observable state | Concrete collaborators/imported frameworks |
ContentView |
User-interface presentation and input forwarding | View |
StackContentView |
User-interface presentation and input forwarding | View |
ThreeColumnContentView |
User-interface presentation and input forwarding | View |
TwoColumnContentView |
User-interface presentation and input forwarding | View |
Recipe |
Represents a feature value or composable behavior | Decodable, Hashable, Identifiable |
Category |
Defines a closed set of feature states or choices | Int, Hashable, CaseIterable, Identifiable, Codable |
Experience |
Defines a closed set of feature states or choices | Int, Identifiable, CaseIterable, Codable |
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 |
|---|---|---|---|
recipes (NavigationCookbook/Models/DataModel.swift:14) |
private(set) |
Read access follows the declaration; writes remain in the private scope. | Inference: allow observation while reserving invariant-changing writes for the owner. |
recipesById (NavigationCookbook/Models/DataModel.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. |
DataModel (NavigationCookbook/Models/DataModel.swift:25) |
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. |
dataURL (NavigationCookbook/Models/DataModel.swift:39) |
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
NavigationCookbook/Models/DataModel.swift:14 — representative boundary
@Observable
final class DataModel {
// ...
private(set) var recipes: [Recipe]
// ...
}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 | NavigationCookbookApp |
The source’s App suffix makes this role explicit. |
| Feature data or observable state | DataModel, NavigationModel |
The source’s Model suffix makes this role explicit. |
| User-interface presentation and input forwarding | ContentView, StackContentView, ThreeColumnContentView, TwoColumnContentView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Binding-based state propagation | NavigationCookbook/Views/ExperiencePicker.swift:12 |
A binding exposes controlled read/write access while the upstream owner remains authoritative. |
Naming conventions
- Types: App: NavigationCookbookApp; Model: DataModel, NavigationModel; View: ContentView, StackContentView, ThreeColumnContentView, TwoColumnContentView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
load,save,encode,recipes. - Files:
NavigationCookbook/NavigationCookbookApp.swift,NavigationCookbook/Models/NavigationModel.swift,NavigationCookbook/Models/DataModel.swift,NavigationCookbook/Views/ContentView.swift,NavigationCookbook/Views/StackContentView.swift,NavigationCookbook/Views/ThreeColumnContentView.swift.
Architecture takeaways
NavigationCookbookAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI 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 |
|---|---|
NavigationCookbook/NavigationCookbookApp.swift |
Cited implementation, NavigationCookbookApp |
NavigationCookbook/Models/NavigationModel.swift |
Cited implementation, Combine, NavigationModel, CodingKeys |
NavigationCookbook/Models/DataModel.swift |
Cited implementation, @Observable, DataModel |
NavigationCookbook/Views/ExperiencePicker.swift |
Cited implementation, ExperiencePicker |
NavigationCookbook/Views/ContentView.swift |
SwiftUI state property wrapper, ContentView, ContentView_Previews |
NavigationCookbook/Models/Category.swift |
SwiftUI, Category |
NavigationCookbook/Views/StackContentView.swift |
StackContentView |
NavigationCookbook/Views/ThreeColumnContentView.swift |
ThreeColumnContentView |
NavigationCookbook/Views/TwoColumnContentView.swift |
TwoColumnContentView |
NavigationCookbook/Models/Recipe.swift |
Recipe, CodingKeys |
NavigationCookbook/Models/Experience.swift |
Experience |
NavigationCookbook/Models/Ingredient.swift |
Ingredient |
NavigationCookbook/Views/ContinueButton.swift |
ContinueButton, ContinueButtonStyle |
NavigationCookbook/Views/ExperiencePickerRow.swift |
ExperiencePickerItem, Label |
NavigationCookbook/Views/RecipeDetail.swift |
RecipeDetail, Content |
NavigationCookbook/Views/RecipeList.swift |
RecipeList, RecipeList_Previews |