Enhancing the accessibility of your SwiftUI app
At a glance
| Item | Summary |
|---|---|
| Purpose | Support advancements in SwiftUI accessibility to make your app accessible to everyone. |
| App architecture | A Swift sample with the source-visible chain App → ContentView → Provider → SwiftUI / SwiftData APIs. |
| Main patterns | Protocol-oriented abstraction |
| Project style | 19 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: @MainActor, Task closure isolated to MainActor, Task, async declaration or closure; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: @Observable, SwiftUI state property wrapper. |
| Key frameworks/packages | SwiftUI, SwiftData, Foundation, AppIntents, WidgetKit; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
└── Sources/
├── App.swift
├── Views/
│ ├── TripsView.swift
│ ├── ContactAlertView.swift
│ ├── BeachesView.swift
│ ├── CommentMessageView.swift
│ └── ContentView.swift
├── Widget/
│ ├── WidgetBundle.swift
│ ├── WidgetIntents.swift
│ ├── BeachView.swift
│ └── Widget.swift
└── Model/
├── Trip.swift
└── Comment.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 53 source declaration(s).
Overall architecture
flowchart LR
N1["App"]
N2["ContentView"]
N3["Provider"]
N4["SwiftUI / SwiftData APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
Sources/App.swift:11 — architecture anchor
@main
struct SwiftUIAccessibilitySampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(for: [Trip.self, Beach.self, Contact.self])
}
}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 Accessibility.
Ownership and state
classDiagram
Location *-- Double : lat
Location *-- Double : long
Location *-- UUID : id
Location *-- String : title
Ownership evidence
Sources/Model/Trip.swift:17 — stored dependency or nearest verified ownership anchor
struct Location: Codable {
var lat: Double
var long: Double
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
Location |
Double (lat) |
owns value state | App/module collaborators |
Location |
Double (long) |
owns value state | App/module collaborators |
Location |
UUID (id) |
owns value state | App/module collaborators |
Location |
String (title) |
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.
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.
| Concern | Source mechanism | Verified placement or handoff | Evidence |
|---|---|---|---|
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | Sources/Model/Trip.swift:92 |
| Main isolation | Task closure isolated to MainActor |
The cited operation explicitly enters a main-actor-isolated region. | Sources/Views/ContactAlertView.swift:237 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | Sources/Views/ContactAlertView.swift:237 |
| Suspension boundary | async declaration or closure |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | Sources/Widget/WidgetIntents.swift:38 |
@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.
Reference code
Sources/Model/Trip.swift:92 — representative execution boundary
protocol TripAttachment {
var imageName: String { get }
var label: String { get }
var color: Color { get }
var configuration: TripAttachmentConfiguration { get }
@MainActor
func performAction()
}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. | Sources/Model/TripRouter.swift:12 |
| State propagation | SwiftUI state property wrapper |
A SwiftUI property wrapper supplies or observes UI state. | Sources/Views/BeachesView.swift:14 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | Sources/App.swift:8 |
| Source import | SwiftData |
The cited file imports this module; runtime use and architectural role are not inferred. | Sources/App.swift:9 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | Sources/Model/Comment.swift:8 |
| Source import | AppIntents |
The cited file imports this module; runtime use and architectural role are not inferred. | Sources/Model/Beach.swift:10 |
| Source import | WidgetKit |
The cited file imports this module; runtime use and architectural role are not inferred. | Sources/Views/BeachesView.swift:10 |
| Source import | AVFoundation |
The cited file imports this module; runtime use and architectural role are not inferred. | Sources/Views/ContactAlertView.swift:10 |
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
Sources/Model/Trip.swift:86 — representative type boundary
protocol TripAttachment {
var imageName: String { get }
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
SwiftUIAccessibilitySampleApp |
Application entry and top-level composition | App |
TripsView |
User-interface presentation and input forwarding | View |
TripDetailsView |
User-interface presentation and input forwarding | View |
TripPostView |
User-interface presentation and input forwarding | View |
AttachmentOverlayView |
User-interface presentation and input forwarding | View |
TripCommentView |
User-interface presentation and input forwarding | View |
UnreadIndicatorView |
User-interface presentation and input forwarding | View |
SidebarView |
User-interface presentation and input forwarding | View |
TripItemView |
User-interface presentation and input forwarding | View |
ContactAlertView |
User-interface presentation and input forwarding | View |
The source explicitly defines local protocol relationships: LocationAttachment → TripAttachment, WebsiteAttachment → TripAttachment.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
beachGradientMix (Sources/Model/Beach.swift:69) |
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. |
beachColors (Sources/Model/Beach.swift:71) |
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. |
commentMessages (Sources/Model/Comment.swift:76) |
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. |
tripWebsite (Sources/Model/Trip.swift:133) |
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
Sources/Model/Beach.swift:69 — representative boundary
extension Beach {
private static let beachGradientMix = 0.25
// ...
}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 | SwiftUIAccessibilitySampleApp |
The source’s App suffix makes this role explicit. |
| Owns media or timeline playback | ContactAlertPlayer |
The source’s Player suffix makes this role explicit. |
| Supplies a capability or framework resource | Provider |
The source’s Provider suffix makes this role explicit. |
| User-interface presentation and input forwarding | AttachmentOverlayView, BeachView, BeachesView, CommentMessageView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Protocol-oriented abstraction | Sources/Model/Trip.swift:100 |
A local protocol and concrete conformance create an explicit capability boundary. |
Naming conventions
- Types: App: SwiftUIAccessibilitySampleApp; Player: ContactAlertPlayer; Provider: Provider; View: AttachmentOverlayView, BeachView, BeachesView, CommentMessageView, ContactAlertHeaderView.
- Protocols:
TripAttachment. - Methods:
editAlerts,toggleOverlay,toggleFavorite,createReply,createNewTrip,togglePlayAction,pathForSound,audioPlayerDidFinishPlaying. - Files:
Sources/Views/TripsView.swift,Sources/Views/ContactAlertView.swift,Sources/Model/Trip.swift,Sources/Views/BeachesView.swift,Sources/Views/CommentMessageView.swift,Sources/Views/ContentView.swift.
Architecture takeaways
Appis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, SwiftData, AppIntents, 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 |
|---|---|
Sources/App.swift |
Cited implementation, SwiftUI, SwiftData, SwiftUIAccessibilitySampleApp |
Sources/Model/Trip.swift |
Cited implementation, TripAttachment, @MainActor, Trip, Location, TripAttachmentConfiguration, LocationAttachment, WebsiteAttachment |
Sources/Model/Beach.swift |
Cited implementation, AppIntents, Beach, Rating |
Sources/Model/Comment.swift |
Cited implementation, Foundation, Comment, Reaction, Reply |
Sources/Views/ContactAlertView.swift |
Task closure isolated to MainActor, Task, AVFoundation, ContactAlertView, ContactAlertHeaderView, ContactAlertPlayer, SoundRow, SoundItem |
Sources/Widget/WidgetIntents.swift |
async declaration or closure, ComposeType, ComposeIntent, ToggleRatingIntent |
Sources/Model/TripRouter.swift |
@Observable, TripRouter |
Sources/Views/BeachesView.swift |
SwiftUI state property wrapper, WidgetKit, BeachesView, BeachComposerItem, BeachView |
Sources/Views/TripsView.swift |
TripsView, TripDetailsView, TripPostView, AttachmentOverlayView, AttachmentImage, TripCommentView, UnreadIndicatorView, SidebarView, TripItemView, TripComposerItem |
Sources/Widget/WidgetBundle.swift |
SwiftUIAccessibilitySampleWidgetBundle |
Sources/Views/CommentMessageView.swift |
CommentMessageView, Configuration, CommentModifier |
Sources/Views/ContentView.swift |
ContentView |
Sources/Widget/BeachView.swift |
BeachView |
Sources/Widget/Widget.swift |
SwiftUIAccessibilitySampleWidget, WidgetView, Provider, Entry |
Sources/Model/Contact.swift |
Contact, Sound, SoundItem |
Sources/Model/Color.swift |
CodableColor, CodableGradient |