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

Finding devices with precision

At a glance

Item Summary
Purpose Leverage the spatial awareness of ARKit and Apple Ultra Wideband Chips in your app to guide users to a nearby device.
App architecture A Swift sample with the source-visible chain NIJetpackAppNIContentViewCoordinatorMPCSessionNearbyInteraction APIs.
Main patterns Delegate or data-source callbacks, Coordinator, Publisher-backed observable state
Project style 8 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: DispatchQueue(label:), DispatchQueue.main.async, @MainActor, Task closure isolated to MainActor, Task; none alone proves a background thread.
State/event model Source-visible mechanisms: ObservableObject, @Published, SwiftUI state property wrapper.
Key frameworks/packages SwiftUI, NearbyInteraction, ARKit, Combine, Foundation; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── NIJetpack/
│   ├── NIJetpackApp.swift
│   ├── NISessionManager.swift
│   ├── Views/
│   │   ├── NICameraAssistanceView.swift
│   │   ├── NIContentView.swift
│   │   ├── NIUnsupportedDeviceView.swift
│   │   └── NICoachingOverlay.swift
│   ├── MultiPeerConnectivitySupport/
│   │   └── MPCSession.swift
│   ├── MathUtilities.swift
│   └── Info.plist
├── Configuration/
│   └── SampleCode.xcconfig
└── NIJetpack.xcodeproj/
    ├── .xcodesamplecode.plist
    └── project.pbxproj

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 4 project/configuration file(s) and 14 source declaration(s).

Overall architecture

Reference code

NIJetpack/NIJetpackApp.swift:10 — architecture anchor

@main
struct NIJetpackApp: App {
    var body: some Scene {
        WindowGroup {
            NIContentView()
        }
    }
}

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 Nearby Interaction.

Ownership and state

Ownership evidence

NIJetpack/NISessionManager.swift:17 — stored dependency or nearest verified ownership anchor

class NISessionManager: NSObject, NISessionDelegate, ObservableObject, ARSessionDelegate {
    // ...
    let findingMode: FindingMode
    // ...
}
Owner Object or state Relationship Mutation authority
NISessionManager FindingMode (findingMode) stores or receives Initialized by the owner; the binding is immutable
NISessionManager DispatchQueue (sessionQueue) creates and retains Initialized by the owner; the binding is immutable
NISessionManager MeasurementQualityEstimator (qualityEstimator) stores or receives Initialized by the owner; the binding is immutable
NISessionManager NISession (session) stores or receives 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
Queue scheduling DispatchQueue(label:) The source constructs a dispatch queue; its label alone does not prove a thread. NIJetpack/MultiPeerConnectivitySupport/MPCSession.swift:45
Queue scheduling DispatchQueue.main.async The source addresses the main dispatch queue. NIJetpack/MultiPeerConnectivitySupport/MPCSession.swift:104
Main isolation @MainActor The cited annotation marks its attached declaration or closure as main-actor isolated. NIJetpack/NISessionManager.swift:32
Main isolation Task closure isolated to MainActor The cited operation explicitly enters a main-actor-isolated region. NIJetpack/NISessionManager.swift:65
Task creation Task The source creates an unstructured task; surrounding context determines inherited actor isolation. NIJetpack/NISessionManager.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

NIJetpack/MultiPeerConnectivitySupport/MPCSession.swift:45 — representative execution boundary

class MPCSession: NSObject, MCSessionDelegate, MCNearbyServiceBrowserDelegate, MCNearbyServiceAdvertiserDelegate {
    // ...
        mpcSessionSerialQueue = DispatchQueue(label: "NIJetpack.mpcQueue", qos: .default)
    // ...
}

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 ObservableObject ObservableObject supplies an observation contract. NIJetpack/NISessionManager.swift:15
State propagation @Published A published property can emit owner-controlled changes. NIJetpack/NISessionManager.swift:32
State propagation SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. NIJetpack/Views/NICameraAssistanceView.swift:18
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. NIJetpack/NIJetpackApp.swift:8
Source import NearbyInteraction The cited file imports this module; runtime use and architectural role are not inferred. NIJetpack/NISessionManager.swift:9
Source import ARKit The cited file imports this module; runtime use and architectural role are not inferred. NIJetpack/NISessionManager.swift:12
Source import Combine The cited file imports this module; runtime use and architectural role are not inferred. NIJetpack/Views/NICameraAssistanceView.swift:13
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. NIJetpack/MultiPeerConnectivitySupport/MPCSession.swift:8

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

NIJetpack/NIJetpackApp.swift:11 — representative type boundary

@main
struct NIJetpackApp: App {
    // ...
            NIContentView()
    // ...
}
Type Responsibility Depends on or conforms to
NIJetpackApp Application entry and top-level composition App
NISessionManager Long-lived feature or framework coordination NSObject, NISessionDelegate, ObservableObject, ARSessionDelegate
NICameraAssistanceView User-interface presentation and input forwarding View
NIARView User-interface presentation and input forwarding UIViewRepresentable
Coordinator Cross-object flow or session coordination NSObject
NIContentView User-interface presentation and input forwarding View
MPCSession Owns a session-scoped interaction NSObject, MCSessionDelegate, MCNearbyServiceBrowserDelegate, MCNearbyServiceAdvertiserDelegate
NIUnsupportedDeviceView User-interface presentation and input forwarding View
MeasurementQualityEstimator Owns feature behavior and collaborator lifecycle Concrete collaborators/imported frameworks
MeasurementQuality Defines a closed set of feature states or choices Concrete collaborators/imported frameworks

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
serviceString (NIJetpack/MultiPeerConnectivitySupport/MPCSession.swift:20) 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.
mcSession (NIJetpack/MultiPeerConnectivitySupport/MPCSession.swift:21) 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.
localPeerID (NIJetpack/MultiPeerConnectivitySupport/MPCSession.swift:22) 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.
mcAdvertiser (NIJetpack/MultiPeerConnectivitySupport/MPCSession.swift:23) 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

NIJetpack/MultiPeerConnectivitySupport/MPCSession.swift:20 — representative boundary

class MPCSession: NSObject, MCSessionDelegate, MCNearbyServiceBrowserDelegate, MCNearbyServiceAdvertiserDelegate {
    // ...
    private let serviceString: String
    // ...
}

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 NIJetpackApp The source’s App suffix makes this role explicit.
Cross-object flow or session coordination Coordinator The source’s Coordinator suffix makes this role explicit.
Long-lived feature or framework coordination NISessionManager The source’s Manager suffix makes this role explicit.
Owns a session-scoped interaction MPCSession The source’s Session suffix makes this role explicit.
User-interface presentation and input forwarding NIARView, NICameraAssistanceView, NIContentView, NIUnsupportedDeviceView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Delegate or data-source callbacks NIJetpack/MultiPeerConnectivitySupport/MPCSession.swift:15 Callback protocols invert event delivery back into the sample’s owner.
Coordinator NIJetpack/Views/NICameraAssistanceView.swift:114 A role-named coordinator centralizes cross-object flow.
Publisher-backed observable state NIJetpack/NISessionManager.swift:32 Published properties notify observers while mutation remains with the state object.

Naming conventions

  • Types: App: NIJetpackApp; Coordinator: Coordinator; Manager: NISessionManager; Session: MPCSession; View: NIARView, NICameraAssistanceView, NIContentView, NIUnsupportedDeviceView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: invalidate, startup, startupMPC, tearDownMpc, setARSession, updateConnectedPeer, connectedToPeer, disconnectedFromPeer.
  • Files: NIJetpack/NIJetpackApp.swift, NIJetpack/NISessionManager.swift, NIJetpack/Views/NICameraAssistanceView.swift, NIJetpack/Views/NIContentView.swift, NIJetpack/MultiPeerConnectivitySupport/MPCSession.swift, NIJetpack/Views/NIUnsupportedDeviceView.swift.

Architecture takeaways

  • NIJetpackApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SwiftUI, NearbyInteraction, ARKit, MultipeerConnectivity 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
NIJetpack/NIJetpackApp.swift Cited implementation, NIJetpackApp, SwiftUI
NIJetpack/NISessionManager.swift Cited implementation, @MainActor, Task closure isolated to MainActor, Task, ObservableObject, @Published, NearbyInteraction, ARKit, NISessionManager, MeasurementQualityEstimator, MeasurementQuality, TimedNIObject
NIJetpack/MultiPeerConnectivitySupport/MPCSession.swift Cited implementation, DispatchQueue(label:), DispatchQueue.main.async, Foundation, MPCSessionConstants, MPCSession
NIJetpack/Views/NICameraAssistanceView.swift Coordinator, SwiftUI state property wrapper, Combine, NICameraAssistanceView, NICameraAssistanceView_Previews, NIARView
NIJetpack/Views/NIContentView.swift FindingMode, NIContentView, NIContentView_Previews
NIJetpack/Views/NIUnsupportedDeviceView.swift NIUnsupportedDeviceView, NIUnsupportedView_Previews
NIJetpack/Views/NICoachingOverlay.swift NICoachingOverlay
NIJetpack/MathUtilities.swift Feature implementation