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

Detecting human body poses in an image

At a glance

Item Summary
Purpose Locate people and the stance of their bodies by analyzing an image with a PoseNet model.
App architecture A Swift sample with the source-visible chain AppDelegateConfigurationViewControllerPopOverPresentationManagerCoreML APIs.
Main patterns View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks, Builder
Project style 19 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: DispatchQueue.global.async, DispatchQueue.main.async; none alone proves a background thread.
State/event model No structured observation or publisher-scheduling marker indexed.
Key frameworks/packages CoreGraphics, UIKit, AVFoundation, CoreML, Vision; these are source dependencies, not architecture labels.

Project structure

Source bundle/
└── PoseFinder/
    ├── App/
    │   └── AppDelegate.swift
    ├── UI/
    │   ├── ConfigurationViewController.swift
    │   ├── PopOverModalViewController.swift
    │   ├── PoseImageView.swift
    │   ├── GradientOverlayView.swift
    │   └── ViewController.swift
    ├── Pose/
    │   ├── PoseBuilder.swift
    │   ├── Joint.swift
    │   └── Pose.swift
    ├── Model/
    │   ├── PoseNetOutput.swift
    │   └── PoseNet.swift
    └── Utils/
        └── VideoCapture.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 25 source declaration(s).

Overall architecture

Reference code

PoseFinder/App/AppDelegate.swift:10 — architecture anchor

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
}

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 Core ML.

Ownership and state

Ownership evidence

PoseFinder/App/AppDelegate.swift:12 — stored dependency or nearest verified ownership anchor

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
}
Owner Object or state Relationship Mutation authority
AppDelegate UIWindow (window) stores or receives App/module collaborators
PopOverPresentationManager UIViewController (presentedViewController) stores or receives App/module collaborators
PopOverPresentationManager UIViewController (presentingViewController) stores or receives App/module collaborators
PopOverPresentationController CGFloat (popOverHeightRatio) owns value state Initialized by the owner; the binding is immutable

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
Queue scheduling DispatchQueue.global.async The source addresses a global dispatch queue; no stable thread identity is implied. PoseFinder/Model/PoseNet.swift:52
Queue scheduling DispatchQueue.main.async The source addresses the main dispatch queue. PoseFinder/Model/PoseNet.swift:65

@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

PoseFinder/Model/PoseNet.swift:52 — representative execution boundary

        DispatchQueue.global(qos: .userInitiated).async {
            // ...
            let input = PoseNetInput(image: image, size: self.modelInputSize)
            // ...
        }

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
Source import CoreGraphics The cited file imports this module; runtime use and architectural role are not inferred. PoseFinder/Extensions+Types/CGImage+Extension.swift:8
Source import UIKit The cited file imports this module; runtime use and architectural role are not inferred. PoseFinder/App/AppDelegate.swift:8
Source import AVFoundation The cited file imports this module; runtime use and architectural role are not inferred. PoseFinder/UI/ViewController.swift:9
Source import CoreML The cited file imports this module; runtime use and architectural role are not inferred. PoseFinder/Model/PoseNet.swift:9
Source import Vision The cited file imports this module; runtime use and architectural role are not inferred. PoseFinder/Model/PoseNet.swift:10
Source import VideoToolbox The cited file imports this module; runtime use and architectural role are not inferred. PoseFinder/UI/ViewController.swift:11

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

PoseFinder/UI/ConfigurationViewController.swift:11 — representative type boundary

protocol ConfigurationViewControllerDelegate: AnyObject {
    func configurationViewController(_ viewController: ConfigurationViewController,
                                     didUpdateConfiguration: PoseBuilderConfiguration)

    func configurationViewController(_ viewController: ConfigurationViewController,
                                     didUpdateAlgorithm: Algorithm)
}
Type Responsibility Depends on or conforms to
AppDelegate Receives callback-driven events UIResponder, UIApplicationDelegate
ConfigurationViewControllerDelegate Defines a capability or collaboration contract AnyObject
VideoCaptureDelegate Defines a capability or collaboration contract AnyObject
PoseNetDelegate Defines a capability or collaboration contract AnyObject
ConfigurationViewController View lifecycle, callbacks, and feature coordination UIViewController
PopOverPresentationManager Long-lived feature or framework coordination NSObject, UIViewControllerTransitioningDelegate
PopOverPresentationController View lifecycle, callbacks, and feature coordination UIPresentationController
PoseImageView User-interface presentation and input forwarding UIImageView
PoseBuilder Incrementally constructs a framework value or graph Concrete collaborators/imported frameworks
GradientOverlayView User-interface presentation and input forwarding UIView

The source explicitly defines local protocol relationships: ViewControllerConfigurationViewControllerDelegate, ViewControllerVideoCaptureDelegate, ViewControllerPoseNetDelegate.

Access control

Symbol Access Verified effect Likely rationale
poseNetMLModel (PoseFinder/Model/PoseNet.swift:40) 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.
imageFeatureName (PoseFinder/Model/PoseNetInput.swift:18) 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.
joints (PoseFinder/Pose/Pose.swift:49) private(set) Read access follows the declaration; writes remain in the private scope. Inference: allow observation while reserving invariant-changing writes for the owner.
candidateRoots (PoseFinder/Pose/PoseBuilder+Multiple.swift:62) 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

PoseFinder/Model/PoseNet.swift:40 — representative boundary

class PoseNet {
    // ...
    private let poseNetMLModel: MLModel
    // ...
}

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
Incrementally constructs a framework value or graph PoseBuilder The source’s Builder suffix makes this role explicit.
View lifecycle, callbacks, and feature coordination ConfigurationViewController, PopOverPresentationController, ViewController The source’s Controller suffix makes this role explicit.
Receives callback-driven events AppDelegate, ConfigurationViewControllerDelegate, PoseNetDelegate, VideoCaptureDelegate The source’s Delegate suffix makes this role explicit.
Long-lived feature or framework coordination PopOverPresentationManager The source’s Manager suffix makes this role explicit.
User-interface presentation and input forwarding GradientOverlayView, PoseImageView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization PoseFinder/UI/ConfigurationViewController.swift:19 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Protocol-oriented abstraction PoseFinder/UI/ViewController.swift:116 A local protocol and concrete conformance create an explicit capability boundary.
Delegate or data-source callbacks PoseFinder/App/AppDelegate.swift:11 Callback protocols invert event delivery back into the sample’s owner.
Builder PoseFinder/Pose/PoseBuilder.swift:11 A builder-named type owns incremental construction.

Naming conventions

  • Types: Builder: PoseBuilder; Controller: ConfigurationViewController, PopOverPresentationController, ViewController; Delegate: AppDelegate, ConfigurationViewControllerDelegate, PoseNetDelegate, VideoCaptureDelegate; Manager: PopOverPresentationManager; View: GradientOverlayView, PoseImageView.
  • Protocols: ConfigurationViewControllerDelegate, VideoCaptureDelegate, PoseNetDelegate.
  • Methods: configurationViewController, viewDidLoad, closeButtonTapped, algorithmValueChanged, jointConfidenceThresholdValueChanged, poseConfidenceThresholdValueChanged, localJointSearchRadiusValueChanged, matchingJointMinimumDistanceValueChanged.
  • Files: PoseFinder/App/AppDelegate.swift, PoseFinder/UI/ConfigurationViewController.swift, PoseFinder/UI/PoseImageView.swift, PoseFinder/Pose/PoseBuilder.swift, PoseFinder/UI/GradientOverlayView.swift, PoseFinder/UI/ViewController.swift.

Architecture takeaways

  • AppDelegate is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches CoreGraphics, UIKit, AVFoundation, CoreML 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
PoseFinder/App/AppDelegate.swift Cited implementation, UIKit, AppDelegate
PoseFinder/UI/ConfigurationViewController.swift ConfigurationViewControllerDelegate, ConfigurationViewController
PoseFinder/Model/PoseNet.swift Cited implementation, DispatchQueue.global.async, DispatchQueue.main.async, CoreML, Vision, PoseNetDelegate, PoseNet
PoseFinder/Model/PoseNetInput.swift Cited implementation, PoseNetInput
PoseFinder/Pose/Pose.swift Cited implementation, Pose, Edge
PoseFinder/Pose/PoseBuilder+Multiple.swift Cited implementation, Feature implementation
PoseFinder/UI/ViewController.swift Cited implementation, AVFoundation, VideoToolbox, ViewController
PoseFinder/Pose/PoseBuilder.swift PoseBuilder
PoseFinder/Extensions+Types/CGImage+Extension.swift CoreGraphics, Feature implementation
PoseFinder/UI/PopOverModalViewController.swift PopOverPresentationManager, PopOverPresentationController
PoseFinder/UI/PoseImageView.swift PoseImageView, JointSegment
PoseFinder/UI/GradientOverlayView.swift GradientOverlayView
PoseFinder/Model/PoseNetOutput.swift PoseNetOutput, Feature, Cell
PoseFinder/Utils/VideoCapture.swift VideoCaptureDelegate, VideoCapture, VideoCaptureError
PoseFinder/Pose/Joint.swift Joint, Name
PoseFinder/Pose/PoseBuilderConfiguration.swift Algorithm, PoseBuilderConfiguration