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

Building peer-to-peer apps

At a glance

Item Summary
Purpose Communicate with nearby devices over a secure, high-throughput, low-latency connection by using Wi-Fi Aware.
App architecture A Swift sample with the source-visible chain Wi-FiAwareSampleAppContentViewConnectionManagerSimulationEngineWiFiAware APIs.
Main patterns Delegate or data-source callbacks, Binding-based state propagation, Actor-isolated state
Project style 13 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
└── Wi-Fi Aware Sample/
    ├── Wi-FiAwareSampleApp.swift
    ├── Simulation/
    │   ├── SimulationEngine.swift
    │   ├── SimulationView.swift
    │   └── SimulationScene.swift
    ├── ContentView.swift
    ├── Networking/
    │   ├── ConnectionManager.swift
    │   ├── DeviceDiscoveryPairingView.swift
    │   ├── NetworkManager.swift
    │   └── WiFiAwareError.swift
    ├── PairedDevices/
    │   └── PairedDevicesView.swift
    └── Extensions/
        ├── SimulationEngine+Extensions.swift
        └── WiFiAware+Extensions.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 5 project/configuration file(s) and 25 source declaration(s).

Overall architecture

Reference code

Wi-Fi Aware Sample/Wi-FiAwareSampleApp.swift:14 — architecture anchor

@main
struct WiFiAwareSampleApp: App {
    // ...
}

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 Wi-Fi Aware.

Ownership and state

Ownership evidence

Wi-Fi Aware Sample/Wi-FiAwareSampleApp.swift:12 — stored dependency or nearest verified ownership anchor

let logger = Logger(subsystem: "com.example.apple-samplecode.Wi-FiAwareSample", category: "App")
Owner Object or state Relationship Mutation authority
Wi-FiAwareSampleApp Logger (logger) creates and retains Initialized by the owner; the binding is immutable
SimulationEngine Mode (mode) stores or receives Initialized by the owner; the binding is immutable
SimulationEngine SimulationScene (scene) stores or receives Owning lexical scope
SimulationEngine NetworkState (networkState) 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

Wi-Fi Aware Sample/Wi-FiAwareSampleApp.swift:15 — representative type boundary

struct WiFiAwareSampleApp: App {
    // ...
}
Type Responsibility Depends on or conforms to
WiFiAwareSampleApp Application entry and top-level composition App
SimulationEngine Owns processing or simulation work Concrete collaborators/imported frameworks
SimulationView User-interface presentation and input forwarding View
ContentView User-interface presentation and input forwarding View
ConnectionManager Long-lived feature or framework coordination Sendable
DeviceDiscoveryPairingView User-interface presentation and input forwarding View
NetworkManager Long-lived feature or framework coordination Concrete collaborators/imported frameworks
PairedDevicesView User-interface presentation and input forwarding View
SimulationScene Scene lifecycle or scene-level composition SKScene, SKPhysicsContactDelegate
ConnectionDetail Represents a feature value or composable behavior Sendable, Equatable

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
simulationService (Wi-Fi Aware Sample/Extensions/WiFiAware+Extensions.swift:14) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
simulationService (Wi-Fi Aware Sample/Extensions/WiFiAware+Extensions.swift:20) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
connections (Wi-Fi Aware Sample/Networking/ConnectionManager.swift:24) 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.
connectionsInfo (Wi-Fi Aware Sample/Networking/ConnectionManager.swift:25) 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

Wi-Fi Aware Sample/Extensions/WiFiAware+Extensions.swift:14 — representative boundary

    public static var simulationService: WAPublishableService {
        allServices[simulationServiceName]!
    }

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 WiFiAwareSampleApp The source’s App suffix makes this role explicit.
Owns processing or simulation work SimulationEngine The source’s Engine suffix makes this role explicit.
Long-lived feature or framework coordination ConnectionManager, NetworkManager The source’s Manager suffix makes this role explicit.
Scene lifecycle or scene-level composition SimulationScene The source’s Scene suffix makes this role explicit.
User-interface presentation and input forwarding ContentView, DeviceDiscoveryPairingView, PairedDevicesView, SimulationView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Delegate or data-source callbacks Wi-Fi Aware Sample/Simulation/SimulationScene.swift:12 Callback protocols invert event delivery back into the sample’s owner.
Binding-based state propagation Wi-Fi Aware Sample/ContentView.swift:34 A binding exposes controlled read/write access while the upstream owner remains authoritative.
Actor-isolated state Wi-Fi Aware Sample/Networking/ConnectionManager.swift:23 Actor annotations make the concurrency ownership boundary explicit.

Naming conventions

  • Types: App: WiFiAwareSampleApp; Engine: SimulationEngine; Manager: ConnectionManager, NetworkManager; Scene: SimulationScene; View: ContentView, DeviceDiscoveryPairingView, PairedDevicesView, SimulationView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: setupEventHandler, startConnectionMonitor, setup, handleLocalEvent, handleConnectionEvent, handleNetworkEvent, run, stopConnection.
  • Files: Wi-Fi Aware Sample/Simulation/SimulationEngine.swift, Wi-Fi Aware Sample/Simulation/SimulationView.swift, Wi-Fi Aware Sample/ContentView.swift, Wi-Fi Aware Sample/Networking/ConnectionManager.swift, Wi-Fi Aware Sample/Networking/DeviceDiscoveryPairingView.swift, Wi-Fi Aware Sample/Networking/NetworkManager.swift.

Architecture takeaways

  • Wi-FiAwareSampleApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches WiFiAware, Network, SwiftUI, SpriteKit 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
Wi-Fi Aware Sample/Wi-FiAwareSampleApp.swift WiFiAwareSampleApp
Wi-Fi Aware Sample/Simulation/SimulationEngine.swift SimulationEngine, ConnectionDetail, LocalEvent, ConnectionEvent
Wi-Fi Aware Sample/Simulation/SimulationView.swift SimulationView, OverlayButtonViewModifier, GlaffEffectViewModifier
Wi-Fi Aware Sample/ContentView.swift ContentView, MenuButton
Wi-Fi Aware Sample/Networking/ConnectionManager.swift ConnectionInfo, ConnectionManager
Wi-Fi Aware Sample/Networking/DeviceDiscoveryPairingView.swift DeviceDiscoveryPairingView, AddDeviceButton
Wi-Fi Aware Sample/Networking/NetworkManager.swift NetworkManager, NetworkEvent
Wi-Fi Aware Sample/PairedDevices/PairedDevicesView.swift PairedDevicesView, DeviceConnectionInfo
Wi-Fi Aware Sample/Extensions/SimulationEngine+Extensions.swift Mode, HostState, ViewerState, NetworkState
Wi-Fi Aware Sample/Simulation/SimulationScene.swift SimulationScene