Patterns across Apple sample code
These corpus-level findings summarize exact labels and source-visible structures from the reviewed sample analyses. Counts are non-exclusive, and a name or import never establishes an architecture by itself. Follow a linked sample page for the source citations behind each classification.
Explore samples · Frameworks · About
Findings across Apple sample code
The completed 2026-07-21 Apple documentation snapshot contains 657 sample pages backed by 643 distinct verified source bundles. Counts below use sample documents as the unit because one Apple source bundle can support more than one documentation page.
Architecture and pattern counts come from exact labels in the source-reviewed sample analyses. They are non-exclusive and are not names Apple necessarily uses for the projects. The source excerpts and per-sample pages remain the evidence for each classification.
Shared collaboration shape
flowchart LR
Entry["App, scene, or controller entry"] --> UI["SwiftUI view or view controller"]
UI -->|"Intent"| Owner["State owner, coordinator, or view model"]
Owner --> Boundary["Framework adapter, session, or provider"]
Boundary --> API["Apple framework"]
API -.->|"Delegate or callback option"| Boundary
Boundary -->|"Result or state"| Owner
Owner -.->|"Observable update option"| UI
Owner -.->|"Direct controller or frame-loop option"| UI
This is a synthesis of recurring relationships, not a universal application pipeline. The dashed routes are independent options. 40 samples (6.1%) carry both reviewed delegate/callback and observable-state labels.
In controller-based samples, the UI and state-owner nodes often collapse into one view controller. Small demonstrations may also combine the owner and framework boundary. Renderer, GPU, and entity-component samples replace the ordinary state feedback path with a frame or update loop.
Representative source evidence
A state owner also serves as the framework callback boundary.
Building a Custom Catalog and Matching Audio — Part 1 - Matching Audio/FoodMath/Matcher.swift:24
class Matcher: NSObject, ObservableObject, SHSessionDelegate {
// ...
private var session: SHSession?
// ...
}A composition root creates state and passes it into the UI.
AVCam: Building a camera app — AVCam/AVCamApp.swift:13
struct AVCamApp: App {
@State private var camera = CameraModel()
var body: some Scene {
WindowGroup {
CameraView(camera: camera)
.task {
await camera.start()
}
}
}
}A StoreKit sample owns an observable Store as app state.
Understanding StoreKit workflows — StoreKitWorkflows/StoreKitWorkflows/StoreKitWorkflowsApp.swift:12
@main
struct StoreKitWorkflowsExampleApp: App {
@State private var store = Store()
var body: some Scene {
WindowGroup {
ContentView()
.environment(store)
// ...
}
}
}A package manifest enforces one-way module dependencies.
Adopting App Intents to support system experiences — AppIntentsTravelTracking/TravelTrackingShared/Package.swift:21
products: [
.library(name: "TravelTrackingCore", targets: ["TravelTrackingCore"]),
.library(name: "TravelTrackingIntents", targets: ["TravelTrackingIntents"]),
.library(name: "TravelTrackingSnippets", targets: ["TravelTrackingSnippets"])
],
targets: [
.target(name: "TravelTrackingCore"),
.target(name: "TravelTrackingIntents", dependencies: ["TravelTrackingCore"]),
.target(name: "TravelTrackingSnippets", dependencies: ["TravelTrackingIntents"])
]Common ownership, access-control, and naming lens
The first three excerpts establish three concrete ownership paths. AVCamApp creates and stores CameraModel in private SwiftUI state, then passes that owner-managed instance into CameraView. Matcher strongly stores its optional SHSession behind private access and declares SHSessionDelegate callback capability; the sample source separately assigns session?.delegate = self. Conformance alone would not establish callback routing or retention. The StoreKit app owns an observable Store in private SwiftUI state; @State proves storage and lifecycle at the app boundary, while the Store declaration establishes observation. The package excerpt separately proves one-way module dependencies.
In Swift, private limits use to the enclosing declaration and same-file extensions of that declaration; fileprivate widens access to the file. A declaration with no modifier is internal. public exposes a declaration only up to the effective visibility of its enclosing declaration. open applies to externally subclassable classes and overridable class members. Each sample page records the modifiers actually present instead of inferring intent from a folder or treating every public token as an effective cross-module API.
Names such as View, ViewController, Model, ViewModel, Coordinator, Manager, Session, and Provider are responsibility clues only. Classification follows who creates, stores, mutates, observes, and delegates state—not the suffix.
Application architectures found
This table includes only architecture labels that occur in the reviewed Apple sample analyses. It omits architectures with no source-supported sample.
| Exact reviewed analysis label | Sample documents | Share | Source boundary |
|---|---|---|---|
| MVC | 14 | 2.1% | Present, but a controller-led shell is only MVC when model, view, and controller responsibilities are source-evident. |
| MVVM | 38 | 5.8% | Present, not dominant. Observation or a type named Model does not by itself establish a view-model boundary. |
| Entity-component-system | 28 | 4.3% | Directly present in a domain-specific subset, especially immersive and game-oriented samples; it is not the general app shell. |
Recurring implementation mechanisms
These non-exclusive counts use exact reviewed labels for mechanisms that shape state ownership, composition, or framework integration.
| Mechanism | Sample documents | Share | What the reviewed label records |
|---|---|---|---|
| Actor isolation | 104 | 15.8% | Actors isolate mutable state or framework work from other executors. |
| Protocol-oriented abstraction | 85 | 12.9% | Protocols describe a replaceable capability or collaboration boundary. |
| SwiftUI scene composition | 83 | 12.6% | SwiftUI scenes provide the top-level declarative composition boundary. |
| UI–RealityKit bridge family | 80 | 12.2% | A UI layer adapts state and interaction into RealityKit content. |
Execution context and imported dependency signals
The Actor isolation row above is a source-reviewed classification, not a count of every actor, Task, or async token. An actor does not by itself mean background-thread execution, and asynchronous syntax does not establish an executor. Per-sample analyses therefore distinguish isolation, scheduling, synchronization, and UI handoffs using cited source.
The table below shows the 12 most prevalent import tokens in the current evidence index. It covers 657 sample documents and 643 distinct verified source bundles. The scanner records Swift module imports and Clang or shader import targets, so these are source-level compilation signals—not runtime-use, package-directness, or architecture claims. Local C-family header tokens ending in .h or .hpp are excluded; remaining tokens may still name a local Swift module or a toolchain library.
| Import token | Sample documents | Source bundles | Document share | Bundle share |
|---|---|---|---|---|
Foundation |
383 | 370 | 58.3% | 57.5% |
UIKit |
335 | 330 | 51.0% | 51.3% |
SwiftUI |
335 | 321 | 51.0% | 49.9% |
Cocoa |
113 | 113 | 17.2% | 17.6% |
AVFoundation |
114 | 111 | 17.4% | 17.3% |
os |
112 | 109 | 17.0% | 17.0% |
RealityKit |
106 | 101 | 16.1% | 15.7% |
simd |
95 | 93 | 14.5% | 14.5% |
Combine |
92 | 92 | 14.0% | 14.3% |
metal_stdlib |
80 | 79 | 12.2% | 12.3% |
ARKit |
64 | 62 | 9.7% | 9.6% |
Metal |
56 | 55 | 8.5% | 8.6% |
Combine appears in 92 sample documents and 92 source bundles; Observation appears in 32 documents and 32 bundles. These imports identify available state or event APIs only. They do not establish a reactive architecture, scheduler choice, ownership model, or actual API use.
Recurring design-pattern and collaboration families
Architecture names describe a whole-app organization; design patterns describe smaller recurring collaborations inside it. These non-exclusive counts use exact reviewed labels: 223 documents (33.9%) match more than one displayed family.
| Design-pattern family | Sample documents | Share | Kind | Evidence boundary |
|---|---|---|---|---|
| Delegation / data source | 314 | 47.8% | Apple collaboration | A host or framework object returns callbacks or asks another object for data; a Delegate suffix alone remains insufficient. |
| Observer / observable state | 159 | 24.2% | State propagation | Combines explicit Observer labels with Swift Observation and publisher-backed state; only the explicit subset is canonical Observer evidence. |
| Boundary bridge | 87 | 13.2% | Framework integration | A reviewed boundary joins frameworks or representations; it is not automatically the classical GoF Bridge object structure. |
| Injection-related | 73 | 11.1% | Construction | Dependencies are supplied or wired outside a consumer; inspect the source to see which side owns the abstraction. |
| Boundary Adapter | 59 | 9.0% | Structural boundary | A concrete type translates APIs, data, callbacks, or platforms. A protocol alone and a type ending Adapter are not sufficient. |
| Coordinator | 32 | 4.9% | Application coordination | Coordinates navigation, presentation, rendering, or framework work; these responsibilities do not form one standardized Coordinator architecture. |
| Strategy / policy | 27 | 4.1% | Behavioral selection | Selects behavior or policy by protocol, function, subtype, table, or configuration; a fixed policy may be only a Strategy-like ingredient. |
| Command / target-action | 12 | 1.8% | Behavioral event routing | Encapsulates or routes actions. Cocoa target-action is a Command adaptation; ordinary methods and GPU command buffers are excluded. |
| Builder | 10 | 1.5% | Creational | Builds a complex value, menu, or resource in staged operations. |
| Factory | 9 | 1.4% | Creational | Centralizes object selection or construction without classifying every initializer or helper as a factory. |
| Facade | 7 | 1.1% | Structural boundary | Presents a smaller app-facing surface over a subsystem or framework. |
| State machine | 7 | 1.1% | Behavioral state | Defines explicit states and transitions; this does not automatically mean the GoF State pattern with polymorphic state objects. |
| Repository | 6 | 0.9% | Data boundary | Centralizes or mediates data access through a repository-labeled or facade role; inspect whether a domain-facing abstraction exists. |
| Template Method family | 6 | 0.9% | Framework hook | A base algorithm or framework lifecycle owns the sequence while a subclass or override supplies selected steps. |
Rarer exact families: Singleton 4, Responder chain 3, Composite 2, Decorator 1, Iterator 1, Memento 1.
Important limits: observable state is broader than canonical Observer; a framework bridge is not automatically the GoF Bridge pattern; a finite state machine is not automatically polymorphic State; and target-action does not make every button closure a Command object.
Observed dependency, data-boundary, and layering patterns
These positive, non-exclusive counts describe the concrete boundary shape recorded in the reviewed source; they are not promoted into a broader whole-application label.
| Observed pattern | Sample documents | Share | What the source-reviewed label records |
|---|---|---|---|
| Dependency injection | 6 | 0.9% | A consumer receives a dependency through explicit construction or configuration. |
| Repository boundary | 6 | 0.9% | A repository-labeled owner or facade centralizes a data-access boundary. |
| Layered organization | 2 | 0.3% | Package or source boundaries establish one-way dependencies between named layers. |
| Composition root | 4 | 0.6% | An app, executable, scene, or controller visibly constructs collaborating objects. |
Adopting App Intents to support system experiences is the clearest package-level example: its SwiftPM manifest enforces Snippets → Intents → Core, and the executable targets act as composition roots.
Two smaller protocol boundaries show different construction choices:
- Accelerating app interactions with App Intents:
ActivityTrackeruses a private platform-strategy protocol and selects the live implementation inside the sample. - Integrating your music app with Apple Intelligence:
SpotlightIndexerreceives aSpotlightWrappingimplementation through its initializer, which also gives tests a substitution seam.
Recurring project and folder structures
These non-exclusive counts come directly from the verified source-tree manifests for 657 sample documents and 643 distinct source bundles. They match path components and project files, not inferred Xcode groups.
| Structure found | Sample documents | Source bundles | Share | Detection boundary |
|---|---|---|---|---|
| Xcode project shell | 639 | 625 | 97.3% | The verified manifest contains an .xcodeproj/project.pbxproj file. |
| Swift package | 46 | 43 | 7.0% | The verified source contains Package.swift. |
| Role-grouped code folders | 124 | 112 | 18.9% | At least two normalized code-folder roles such as Views, Models, Services, or Stores. |
| Explicit shared code | 54 | 54 | 8.2% | A manifest path has an exact Shared, Shared Code, Shared Files, Shared Source, or Shared Sources component. |
| Platform siblings | 59 | 59 | 9.0% | At least two explicit iOS, iPadOS, macOS, watchOS, tvOS, or visionOS directory components. |
| Tutorial stages | 5 | 5 | 0.8% | At least two Part-number, start, or final stage labels appear in directory names. |
No single folder convention dominates every sample. The common shape is an Xcode target-oriented shell with pragmatic role or feature folders; multi-product samples add shared, platform, extension, or Swift-package boundaries when needed.
Representative verified source trees:
Role folders plus separate executable targets. AVCam: Building a camera app
AVCam/
├── Capture/
├── Model/
├── Support/
└── Views/
AVCamCaptureExtension/
AVCamControlCenterExtension/
Swift package targets with one-way dependencies. Adopting App Intents to support system experiences
TravelTrackingShared/
├── Package.swift
└── Sources/
├── TravelTrackingCore/
├── TravelTrackingIntents/
└── TravelTrackingSnippets/
Feature and technical-role grouping. Creating a spatial drawing app with RealityKit
RealityKitDrawingApp/
├── Brushes/
├── Canvas/
├── Document/
├── UI/
├── Utilities/
└── Packages/RealityKitContent/
Store names and reducer-style flow found
Parsed declarations in 32 sample documents include a type whose name ends in Store. The role is intentionally broad in Apple samples: purchase and entitlement state, persistence, framework-facing ownership, sync, a storefront view, a retail-location model, and a static cache all occur.
Understanding StoreKit workflows keeps an observable Store in private app-owned state and supplies it through the SwiftUI environment. The type itself is internal, so public members inside it cannot be more visible than that enclosing type.
Origami provides a separate positive event/effect example: an observable Orchestrator accepts typed events, privately reduces them into state changes and typed effects, then privately executes those effects.
Origami/Models/Orchestrator.swift:165
func send(_ event: OrchestratorEvent) {
// ...
let effects = reduce(event)
guard !effects.isEmpty else { return }
currentTask = Task {
for effect in effects {
await execute(effect)
// ...
}
}
}Naming roles found in source
The table scans parsed declaration names from 657 sample evidence records. Suffixes are matched longest-first and are mutually exclusive: CameraViewModel counts as ViewModel, not Model, and each sample counts at most once per role.
| Declaration suffix | Sample documents | Share | Observed responsibility clue |
|---|---|---|---|
Delegate |
328 | 49.9% | A lifecycle or callback receiver; many are AppDelegate or SceneDelegate entry types. |
ViewController |
287 | 43.7% | A UIKit/AppKit view and interaction lifecycle owner. |
App |
284 | 43.2% | An application or SwiftUI composition entry type. |
Model |
119 | 18.1% | A data or state role; ViewModel names are counted separately. |
Manager |
78 | 11.9% | A broad resource or framework-lifecycle owner whose exact scope needs inspection. |
Renderer |
71 | 10.8% | A graphics or frame-loop owner. |
Controller |
66 | 10.0% | A non-view-controller coordination, document, window, or feature owner. |
Provider |
58 | 8.8% | A type that supplies data, content, configuration, or framework integration. |
ViewModel |
42 | 6.4% | A view-facing state or behavior owner; inspect dependencies before calling it MVVM. |
Store |
32 | 4.9% | A broad role noun used for state, persistence, commerce, storefront views, caches, and domain models; the name alone does not establish one mutation model. |
Coordinator |
28 | 4.3% | A workflow, navigation, presentation, rendering, or technical orchestrator. |
DataSource |
17 | 2.6% | A collaborator that supplies data to a view or framework object. |
Session |
14 | 2.1% | A connection, capture, conversation, or other bounded runtime lifetime. |
Service |
13 | 2.0% | An operation boundary around a capability or framework. |
Adapter |
4 | 0.6% | A type that translates between framework, platform, or feature boundaries. |
Repository |
2 | 0.3% | A type that centralizes or mediates data access; inspect whether it owns a domain-facing abstraction. |
Observed naming rules:
- A suffix is a responsibility clue, so the analysis checks construction, lifetime, mutation authority, inputs, outputs, and collaborators.
ViewControllernormally owns a UIKit/AppKit view lifecycle.ViewModelis used only when source establishes a view-facing state or behavior owner.Coordinatornames navigation, presentation, rendering, and framework orchestration; its prefix and collaborators define the actual scope.ManagerandStoreare broad nouns. Their source-visible responsibilities matter more than the suffix.- Access control is reported separately from naming: app implementation types are commonly implicit
internalor narrower, while cross-module APIs need an effectivepublicoropenboundary.
Counts represent sample documents unless a source-bundle column is shown. Detailed ownership, access control, and source evidence remain in each linked sample analysis.