Bringing multiple windows to your SwiftUI app
At a glance
| Item | Summary |
|---|---|
| Purpose | Compose rich views by reacting to state changes and customize your app’s scene presentation and behavior on iPadOS and macOS. |
| App architecture | A Swift sample with the source-visible chain BookClubApp → ArcView → NavigationModel → SeededRandomNumberGenerator → SwiftUI APIs. |
| Main patterns | Factory, Publisher-backed observable state, Actor-isolated state |
| Project style | 36 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
└── BookClub/
├── BookClubApp.swift
├── Views/
│ ├── CircularProgressView.swift
│ ├── LinearProgressView.swift
│ ├── StackedProgressView.swift
│ ├── BookDetail/
│ │ └── BookDetailHeader.swift
│ └── BookCover.swift
└── Models/
├── NavigationModel.swift
├── ProgressEditorModel.swift
├── ReadingListModel.swift
├── CurrentlyReading.swift
├── ReadingProgress.swift
└── ReadingActivityItem.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 5 project/configuration file(s) and 51 source declaration(s).
Overall architecture
flowchart LR
N1["BookClubApp"]
N2["ArcView"]
N3["NavigationModel"]
N4["SeededRandomNumberGenerator"]
N5["SwiftUI APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
Reference code
BookClub/BookClubApp.swift:11 — architecture anchor
@main
struct BookClubApp: 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
BookClubApp *-- ReadingListModel : dataModel
NavigationModel o-- NavigationSplitViewVisibility : columnVisibility
NavigationModel o-- Category : selectedCategory
NavigationModel *-- Set : selectedBookIds
Ownership evidence
BookClub/BookClubApp.swift:13 — stored dependency or nearest verified ownership anchor
private var dataModel = ReadingListModel()| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
BookClubApp |
ReadingListModel (dataModel) |
creates and retains | Owning lexical scope |
NavigationModel |
NavigationSplitViewVisibility (columnVisibility) |
stores or receives | App/module collaborators |
NavigationModel |
Category (selectedCategory) |
stores or receives | App/module collaborators |
NavigationModel |
Set (selectedBookIds) |
owns value 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
BookClub/BookClubApp.swift:12 — representative type boundary
struct BookClubApp: App {
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
BookClubApp |
Application entry and top-level composition | App |
CircularProgressView |
User-interface presentation and input forwarding | View |
ArcView |
User-interface presentation and input forwarding | View |
NavigationModel |
Feature data or observable state | Codable, ObservableObject |
ProgressEditorModel |
Feature data or observable state | Hashable |
LinearReadingProgressView |
User-interface presentation and input forwarding | View |
StackedProgressView |
User-interface presentation and input forwarding | View |
ReadingListModel |
Feature data or observable state | ObservableObject |
MockFactory |
Constructs a selected implementation | Concrete collaborators/imported frameworks |
SeededRandomNumberGenerator |
Generates feature data or resources | RandomNumberGenerator |
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 |
|---|---|---|---|
dataModel (BookClub/BookClubApp.swift:13) |
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. |
id (BookClub/Models/Book.swift:11) |
private(set) |
Read access follows the declaration; writes remain in the private scope. | Inference: allow observation while reserving invariant-changing writes for the owner. |
random (BookClub/Models/CurrentlyReading.swift:88) |
fileprivate |
Use is restricted to this source file. | Inference: share with same-file helpers or extensions without exposing the symbol module-wide. |
book (BookClub/Models/CurrentlyReading.swift:150) |
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. |
Reference code
BookClub/BookClubApp.swift:13 — representative boundary
private var dataModel = ReadingListModel()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 | BookClubApp |
The source’s App suffix makes this role explicit. |
| Constructs a selected implementation | MockFactory |
The source’s Factory suffix makes this role explicit. |
| Generates feature data or resources | SeededRandomNumberGenerator |
The source’s Generator suffix makes this role explicit. |
| Feature data or observable state | NavigationModel, ProgressEditorModel, ReadingListModel |
The source’s Model suffix makes this role explicit. |
| User-interface presentation and input forwarding | ArcView, CircularProgressView, LinearReadingProgressView, StackedProgressView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Factory | BookClub/Models/CurrentlyReading.swift:101 |
A factory-named type owns implementation construction. |
| Publisher-backed observable state | BookClub/Models/CurrentlyReading.swift:12 |
Published properties notify observers while mutation remains with the state object. |
| Actor-isolated state | BookClub/Views/ShareButton.swift:35 |
Actor annotations make the concurrency ownership boundary explicit. |
Naming conventions
- Types: App: BookClubApp; Factory: MockFactory; Generator: SeededRandomNumberGenerator; Model: NavigationModel, ProgressEditorModel, ReadingListModel; View: ArcView, CircularProgressView, LinearReadingProgressView, StackedProgressView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
makeBody,path,inset,encode,present,dismiss,togglePresentation,foregroundStyle. - Files:
BookClub/BookClubApp.swift,BookClub/Views/CircularProgressView.swift,BookClub/Models/NavigationModel.swift,BookClub/Models/ProgressEditorModel.swift,BookClub/Views/StackedProgressView.swift,BookClub/Models/ReadingListModel.swift.
Architecture takeaways
BookClubAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, Charts 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 |
|---|---|
BookClub/BookClubApp.swift |
BookClubApp |
BookClub/Views/CircularProgressView.swift |
CircularProgressView, CircularProgressViewStyle, ArcView, Arc, CircularProgressView_Previews |
BookClub/Models/NavigationModel.swift |
NavigationModel, CodingKeys |
BookClub/Models/ProgressEditorModel.swift |
ProgressEditorModel, DismissAction |
BookClub/Views/LinearProgressView.swift |
LinearReadingProgressView, LinearReadingProgressViewStyle, LinearReadingProgressView_Previews |
BookClub/Views/StackedProgressView.swift |
StackedProgressView, StackedProgressViewStyle, StackedProgressView_Previews |
BookClub/Models/ReadingListModel.swift |
ReadingListModel |
BookClub/Views/BookDetail/BookDetailHeader.swift |
BookDetailHeader, BookCover, ButtonFooter, BookDescriptionSheet, BookDetailHeader_Previews |
BookClub/Models/CurrentlyReading.swift |
CurrentlyReading, MockFactory, SeededRandomNumberGenerator |
BookClub/Models/ReadingProgress.swift |
ReadingProgress, EntriesByDate, Entry |