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.

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.

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

    private let poseNetMLModel: MLModel

    init() throws {
        poseNetMLModel = try PoseNetMobileNet075S16FP16(configuration: .init()).model
    }

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 AppDelegate
PoseFinder/UI/ConfigurationViewController.swift ConfigurationViewControllerDelegate, ConfigurationViewController
PoseFinder/UI/PopOverModalViewController.swift PopOverPresentationManager, PopOverPresentationController
PoseFinder/UI/PoseImageView.swift PoseImageView, JointSegment
PoseFinder/Pose/PoseBuilder.swift PoseBuilder
PoseFinder/UI/GradientOverlayView.swift GradientOverlayView
PoseFinder/UI/ViewController.swift ViewController
PoseFinder/Model/PoseNetOutput.swift PoseNetOutput, Feature, Cell
PoseFinder/Utils/VideoCapture.swift VideoCaptureDelegate, VideoCapture, VideoCaptureError
PoseFinder/Model/PoseNet.swift PoseNetDelegate, PoseNet