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 NIJetpackApp → NIContentView → Coordinator → MPCSession → NearbyInteraction APIs. |
| Main patterns | Delegate or data-source callbacks, Coordinator, Publisher-backed observable state, Actor-isolated state |
| Project style | 8 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
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
flowchart LR
N1["NIJetpackApp"]
N2["NIContentView"]
N3["Coordinator"]
N4["MPCSession"]
N5["NearbyInteraction APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
N4 --> N5
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
classDiagram
NISessionManager o-- FindingMode : findingMode
NISessionManager *-- DispatchQueue : sessionQueue
NISessionManager o-- MeasurementQualityEstimator : qualityEstimator
NISessionManager o-- NISession : session
Ownership evidence
NIJetpack/NISessionManager.swift:17 — stored dependency or nearest verified ownership anchor
let findingMode: FindingMode
let sessionQueue = DispatchQueue(label: "NIJetpack.sessionManager.NISessionQueue", qos: .userInitiated)
let qualityEstimator: MeasurementQualityEstimator?
// Mutable properties.
var session: NISession?
var peerDiscoveryToken: NIDiscoveryToken?| 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.
Class and protocol design
NIJetpack/NIJetpackApp.swift:11 — representative type boundary
struct NIJetpackApp: App {
var body: some Scene {
WindowGroup {
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
private let serviceString: String
private let mcSession: MCSession
private let localPeerID: MCPeerID
private let mcAdvertiser: MCNearbyServiceAdvertiser
private let discoveryInfoIdentity: String
private let maxNumPeers: IntSwift 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. |
| Actor-isolated state | NIJetpack/NISessionManager.swift:32 |
Actor annotations make the concurrency ownership boundary explicit. |
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
NIJetpackAppis 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 |
NIJetpackApp |
NIJetpack/NISessionManager.swift |
NISessionManager, MeasurementQualityEstimator, MeasurementQuality, TimedNIObject |
NIJetpack/Views/NICameraAssistanceView.swift |
NICameraAssistanceView, NICameraAssistanceView_Previews, NIARView, Coordinator |
NIJetpack/Views/NIContentView.swift |
FindingMode, NIContentView, NIContentView_Previews |
NIJetpack/MultiPeerConnectivitySupport/MPCSession.swift |
MPCSessionConstants, MPCSession |
NIJetpack/Views/NIUnsupportedDeviceView.swift |
NIUnsupportedDeviceView, NIUnsupportedView_Previews |
NIJetpack/Views/NICoachingOverlay.swift |
NICoachingOverlay |
NIJetpack/MathUtilities.swift |
Feature implementation |