Sample CodeiOS, iPadOS, Mac Catalyst, macOSReviewed 2026-07-21View on Apple Developer

Creating accessible views

At a glance

Item Summary
Purpose Make your app accessible to everyone by applying accessibility modifiers to your SwiftUI views.
App architecture A Swift sample with the source-visible chain AccessibilityExamplesExamplesViewColorModelSwiftUI APIs.
Main patterns View-controller organization, Binding-based state propagation
Project style 20 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
└── SwiftUIAccessibilityExamples/
    ├── Shared/
    │   ├── AccessibilityExamples.swift
    │   ├── CustomControlsExample.swift
    │   ├── EnvironmentExample.swift
    │   ├── RotorsExample.swift
    │   ├── ForEachExample.swift
    │   ├── CanvasExample.swift
    │   ├── CustomContentExample.swift
    │   ├── FocusExample.swift
    │   └── SortPriorityExample.swift
    ├── Mac/
    │   ├── RepresentableExample_macOS.swift
    │   └── AccessibilityExamplesView_macOS.swift
    └── iOS/
        └── RepresentableExample_iOS.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 7 project/configuration file(s) and 61 source declaration(s).

Overall architecture

Reference code

SwiftUIAccessibilityExamples/Shared/AccessibilityExamples.swift:12 — architecture anchor

@main
struct AccessibilityExamplesApp: App {
    var body: some Scene {
        WindowGroup {
            ExamplesView()
        }
    }
}

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

Ownership evidence

SwiftUIAccessibilityExamples/Shared/AccessibilityExamples.swift:25 — stored dependency or nearest verified ownership anchor

struct Example {
    var name: String
    // ...
}
Owner Object or state Relationship Mutation authority
Example String (name) owns value state App/module collaborators
Example AnyView (view) stores or receives App/module collaborators
Example Bool (wantsScrollView) owns value state App/module collaborators
Example Bool (wantsPadding) 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

SwiftUIAccessibilityExamples/Shared/AccessibilityExamples.swift:13 — representative type boundary

struct AccessibilityExamplesApp: App {
    var body: some Scene {
        WindowGroup {
            ExamplesView()
        }
    }
}
Type Responsibility Depends on or conforms to
AccessibilityExamplesApp Application entry and top-level composition App
AccessibilityElementView User-interface presentation and input forwarding View
ColorModel Feature data or observable state Concrete collaborators/imported frameworks
ReduceTransparencyView User-interface presentation and input forwarding View
Model Feature data or observable state Concrete collaborators/imported frameworks
RepresentableNSView User-interface presentation and input forwarding NSView
RepresentableNSViewController View lifecycle, callbacks, and feature coordination NSViewController
RepresentableView User-interface presentation and input forwarding NSViewRepresentable
RepresentableViewController View lifecycle, callbacks, and feature coordination NSViewControllerRepresentable
RepresentableUIView User-interface presentation and input forwarding UIView

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
example (SwiftUIAccessibilityExamples/Mac/AccessibilityExamplesView_macOS.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.
text (SwiftUIAccessibilityExamples/Shared/AccessibilityExamples.swift:66) 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.
content (SwiftUIAccessibilityExamples/Shared/AccessibilityExamples.swift:67) 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.
onState (SwiftUIAccessibilityExamples/Shared/ContainerExample.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

SwiftUIAccessibilityExamples/Mac/AccessibilityExamplesView_macOS.swift:12 — representative boundary

    private var example: Example

    init(_ example: Example) {
        self.example = example
    }

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 AccessibilityExamplesApp The source’s App suffix makes this role explicit.
View lifecycle, callbacks, and feature coordination RepresentableNSViewController, RepresentableUIViewController, RepresentableViewController The source’s Controller suffix makes this role explicit.
Feature data or observable state ColorModel, Model The source’s Model suffix makes this role explicit.
User-interface presentation and input forwarding AccessibilityElementView, ExampleView, ExamplesView, ReduceTransparencyView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization SwiftUIAccessibilityExamples/Mac/RepresentableExample_macOS.swift:42 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Binding-based state propagation SwiftUIAccessibilityExamples/Shared/CustomControlsExample.swift:96 A binding exposes controlled read/write access while the upstream owner remains authoritative.

Naming conventions

  • Types: App: AccessibilityExamplesApp; Controller: RepresentableNSViewController, RepresentableUIViewController, RepresentableViewController; Model: ColorModel, Model; View: AccessibilityElementView, ExampleView, ExamplesView, ReduceTransparencyView, RepresentableNSView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: updateLayer, loadView, makeNSView, updateNSView, makeNSViewController, updateNSViewController, makeUIViewController, updateUIViewController.
  • Files: SwiftUIAccessibilityExamples/Shared/CustomControlsExample.swift, SwiftUIAccessibilityExamples/Shared/EnvironmentExample.swift, SwiftUIAccessibilityExamples/Shared/RotorsExample.swift, SwiftUIAccessibilityExamples/Shared/ForEachExample.swift, SwiftUIAccessibilityExamples/Shared/CanvasExample.swift, SwiftUIAccessibilityExamples/Shared/CustomContentExample.swift.

Architecture takeaways

  • AccessibilityExamples is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SwiftUI, AppKit, UIKit 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
SwiftUIAccessibilityExamples/Shared/AccessibilityExamples.swift AccessibilityExamplesApp, Example, LabeledExample, AccessibilityElementView
SwiftUIAccessibilityExamples/Shared/CustomControlsExample.swift CustomControlsExample, TrackSlider, TrackSwitch, TrackShape, BackgroundTrack, OverlayTrack, Knob, CustomControlsExample_Previews
SwiftUIAccessibilityExamples/Shared/EnvironmentExample.swift ColorModel, Value, DifferentiateWithoutColorExample, ReduceTransparencyView, ReduceMotionExample, IgnoreInvertColorsExample, IncreaseContrastExample, AccessibilityFeaturesExample, EnvironmentExample
SwiftUIAccessibilityExamples/Shared/RotorsExample.swift Model, Value, StackExample, RotorExampleNavigation, RotorsExample, RotorsExample
SwiftUIAccessibilityExamples/Mac/RepresentableExample_macOS.swift RepresentableNSView, RepresentableNSViewController, RepresentableView, RepresentableViewController
SwiftUIAccessibilityExamples/Shared/ForEachExample.swift ForEachExample, Activity, ActivityCell, ForEachExample_Previews
SwiftUIAccessibilityExamples/iOS/RepresentableExample_iOS.swift RepresentableUIView, RepresentableUIViewController, RepresentableViewController, RepresentableView
SwiftUIAccessibilityExamples/Shared/CanvasExample.swift CanvasExample, LinesOfCodeGraph, CanvasExample_Previews
SwiftUIAccessibilityExamples/Shared/CustomContentExample.swift Model, Illustration, CustomContentExample
SwiftUIAccessibilityExamples/Shared/FocusExample.swift Model, Notification, FocusExample