Add rich graphics to your SwiftUI app
At a glance
| Item | Summary |
|---|---|
| Purpose | Make your apps stand out by adding background materials, vibrancy, custom graphics, and animations. |
| App architecture | A Swift sample with the source-visible chain GradientBuilderApp → ContentView → GradientModelStore → SwiftUI APIs. |
| Main patterns | Central store, Binding-based state propagation |
| Project style | 13 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
└── Shared/
├── GradientBuilderApp.swift
├── Model/
│ ├── GradientModel.swift
│ └── GradientModelStore.swift
└── Views/
├── ContentView.swift
├── GradientDetailView.swift
├── SystemColorPicker.swift
├── Visualizers/
│ ├── Particles/
│ │ ├── ParticleModel.swift
│ │ └── Particle.swift
│ ├── ShapeVisualizer.swift
│ └── ParticleVisualizer.swift
├── GradientControl.swift
└── Visualizer.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 6 project/configuration file(s) and 21 source declaration(s).
Overall architecture
flowchart LR
N1["GradientBuilderApp"]
N2["ContentView"]
N3["GradientModelStore"]
N4["SwiftUI APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
Shared/GradientBuilderApp.swift:10 — architecture anchor
@main
struct GradientBuilderApp: 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
Stop o-- Color : color
Stop *-- Double : location
Stop *-- Int : id
Stop *-- Array : stops
Ownership evidence
Shared/Model/GradientModel.swift:14 — stored dependency or nearest verified ownership anchor
struct Stop: Equatable, Identifiable {
// ...
var color: Color
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
Stop |
Color (color) |
stores or receives | App/module collaborators |
Stop |
Double (location) |
owns value state | App/module collaborators |
Stop |
Int (id) |
owns value state | App/module collaborators |
Stop |
Array (stops) |
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
Shared/GradientBuilderApp.swift:11 — representative type boundary
struct GradientBuilderApp: App {
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
GradientBuilderApp |
Application entry and top-level composition | App |
GradientModel |
Feature data or observable state | Equatable, Identifiable |
ContentView |
User-interface presentation and input forwarding | View |
GradientDetailView |
User-interface presentation and input forwarding | View |
GradientModelStore |
Centralized state or persistence access | Concrete collaborators/imported frameworks |
ParticleModel |
Feature data or observable state | ObservableObject |
Stop |
Represents a feature value or composable behavior | Equatable, Identifiable |
SystemColorList |
Represents a feature value or composable behavior | View |
Empty |
Represents a feature value or composable behavior | View |
SystemColorPicker |
Represents a feature value or composable behavior | View |
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 |
|---|---|---|---|
store (Shared/GradientBuilderApp.swift:12) |
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. |
isPlaying (Shared/Views/ContentView.swift:12) |
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. |
oldLocation (Shared/Views/GradientControl.swift:55) |
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. |
isEditing (Shared/Views/GradientDetailView.swift:12) |
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
Shared/GradientBuilderApp.swift:12 — representative boundary
@main
struct GradientBuilderApp: App {
@State private var store = GradientModelStore.defaultStore
// ...
}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 | GradientBuilderApp |
The source’s App suffix makes this role explicit. |
| Feature data or observable state | GradientModel, ParticleModel |
The source’s Model suffix makes this role explicit. |
| Centralized state or persistence access | GradientModelStore |
The source’s Store suffix makes this role explicit. |
| User-interface presentation and input forwarding | ContentView, GradientDetailView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Central store | Shared/Model/GradientModelStore.swift:10 |
A store-named type centralizes feature state or persistence. |
| Binding-based state propagation | Shared/Views/ContentView.swift:11 |
A binding exposes controlled read/write access while the upstream owner remains authoritative. |
Naming conventions
- Types: App: GradientBuilderApp; Model: GradientModel, ParticleModel; Store: GradientModelStore; View: ContentView, GradientDetailView.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
append,remove,update,add,make,forEachParticle,path. - Files:
Shared/GradientBuilderApp.swift,Shared/Model/GradientModel.swift,Shared/Views/ContentView.swift,Shared/Views/GradientDetailView.swift,Shared/Model/GradientModelStore.swift,Shared/Views/SystemColorPicker.swift.
Architecture takeaways
GradientBuilderAppis 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 |
|---|---|
Shared/GradientBuilderApp.swift |
GradientBuilderApp |
Shared/Model/GradientModel.swift |
GradientModel, Stop |
Shared/Views/ContentView.swift |
ContentView, ContentView_Previews |
Shared/Views/GradientDetailView.swift |
GradientDetailView, Detail_Previews |
Shared/Model/GradientModelStore.swift |
GradientModelStore |
Shared/Views/SystemColorPicker.swift |
SystemColorList, Empty, SystemColorPicker, ColorOption |
Shared/Views/Visualizers/Particles/ParticleModel.swift |
ParticleModel |
Shared/Views/GradientControl.swift |
GradientControl, StopHandle, Triangle |
Shared/Views/Visualizers/ShapeVisualizer.swift |
ShapeVisualizer, SymbolState, Entry |
Shared/Views/Visualizers/ParticleVisualizer.swift |
ParticleVisualizer, ParticleView_Previews |