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. |
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 {
// ...
}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
var selectedCategory: Category?
/// The homogenous navigation state used by the app's navigation stacks.
var recipePath: [Recipe]
/// The leading columns' visibility state used by the app's navigation split views.
var columnVisibility: NavigationSplitViewVisibility| 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.
Class and protocol design
NavigationCookbook/NavigationCookbookApp.swift:12 — representative type boundary
struct NavigationCookbookApp: App {
// ...
}| 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
private(set) var recipes: [Recipe]
/// A dictionary of recipes, each grouped by its associated unique identifier.
private var recipesById: [Recipe.ID: Recipe] = [:]
/// The shared singleton data model object.
static let shared: DataModel = {
// ...
}()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 |
NavigationCookbookApp |
NavigationCookbook/Models/NavigationModel.swift |
NavigationModel, CodingKeys |
NavigationCookbook/Models/DataModel.swift |
DataModel |
NavigationCookbook/Views/ContentView.swift |
ContentView, ContentView_Previews |
NavigationCookbook/Views/StackContentView.swift |
StackContentView |
NavigationCookbook/Views/ThreeColumnContentView.swift |
ThreeColumnContentView |
NavigationCookbook/Views/TwoColumnContentView.swift |
TwoColumnContentView |
NavigationCookbook/Models/Recipe.swift |
Recipe, CodingKeys |
NavigationCookbook/Models/Category.swift |
Category |
NavigationCookbook/Models/Experience.swift |
Experience |