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

Configuring a Wi-Fi accessory to join a network

At a glance

Item Summary
Purpose Associate an iOS device with an accessory’s network to deliver network configuration information.
App architecture A Swift sample bundle with entry-bearing project variants BrandXAccessory, BrandXAccessorySetup, each leading to Network / NetworkExtension APIs.
Main patterns View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks
Project style 25 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
├── BrandXAccessory/
│   ├── AppDelegate.swift
│   └── UI/
│       └── ViewControllers/
│           ├── BrandXAccessoryBaseViewController.swift
│           ├── BrandXAccessoryConfigureViewController.swift
│           ├── BrandXAccessoryDoneViewController.swift
│           └── BrandXAccessorySetupViewController.swift
└── BrandXAccessorySetup/
    ├── AppDelegate.swift
    ├── Network/
    │   ├── AccessoryNetworkManager.swift
    │   └── DeviceNetworkManager.swift
    ├── UI/
    │   └── ViewControllers/
    │       ├── QRScanningViewController.swift
    │       └── SetupBaseViewController.swift
    ├── Location/
    │   └── LocationManager.swift
    └── SceneDelegate.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 10 project/configuration file(s) and 30 source declaration(s).

Overall architecture

Reference code

BrandXAccessory/AppDelegate.swift:10 — architecture anchor

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    
    func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
        return true
    }
}

Interpretation

The branches represent separate entry-bearing project variants in the downloaded bundle, not runtime calls between those variants. Each branch is intentionally collapsed at the documented framework boundary; the detailed target-local flow remains in the cited files. Ownership is claimed only where the next section cites a stored property or assignment.

Ownership and state

Ownership evidence

BrandXAccessorySetup/Network/AccessoryNetworkManager.swift:17 — stored dependency or nearest verified ownership anchor

final class AccessoryNetworkManager {
    // ...
    public weak var delegate: Delegate?
    // ...
}
Owner Object or state Relationship Mutation authority
AccessoryNetworkManager Delegate (delegate) holds a non-owning reference The referenced object’s lifecycle is owned elsewhere
AccessoryNetworkManager Bool (isReady) owns value state App/module collaborators
AccessoryNetworkManager String (status) owns value state App/module collaborators
QRScanningViewController QRScanningDelegate (delegate) holds a non-owning reference The referenced object’s lifecycle is owned elsewhere

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

BrandXAccessorySetup/Network/AccessoryNetworkManager.swift:54 — representative type boundary

protocol AccessoryNetworkManagerDelegate: AnyObject {
    func accessoryNetworkManagerDidUpdate(acessoryNetworkManager: AccessoryNetworkManager)
}
Type Responsibility Depends on or conforms to
AppDelegate Receives callback-driven events NSObject, NSApplicationDelegate
AppDelegate Receives callback-driven events UIResponder, UIApplicationDelegate
AccessoryNetworkManagerDelegate Defines a capability or collaboration contract AnyObject
QRScanningDelegate Defines a capability or collaboration contract AnyObject
WebSocketListenerDelegate Defines a capability or collaboration contract AnyObject
WebSocketConnectionDelegate Defines a capability or collaboration contract AnyObject
AccessoryNetworkManager Long-lived feature or framework coordination Concrete collaborators/imported frameworks
QRScanningViewController View lifecycle, callbacks, and feature coordination UIViewController
BrandXAccessoryBaseViewController View lifecycle, callbacks, and feature coordination NSViewController
BrandXAccessoryConfigureViewController View lifecycle, callbacks, and feature coordination BrandXAccessoryBaseViewController

The source explicitly defines local protocol relationships: BrandXAccessoryConfigureViewControllerWebSocketListenerDelegate, BrandXAccessoryConfigureViewControllerWebSocketConnectionDelegate, SetupHotspotConnectViewControllerAccessoryNetworkManagerDelegate, SetupQRCodeViewControllerQRScanningDelegate, SetupSendDataViewControllerWebSocketConnectionDelegate.

Access control

Symbol Access Verified effect Likely rationale
websocketListener (BrandXAccessory/Network/WebSocketListener.swift:15) 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.
didListenerFail (BrandXAccessory/Network/WebSocketListener.swift:16) 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.
didConnectionSetup (BrandXAccessory/Network/WebSocketListener.swift:17) 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.
shared (BrandXAccessory/Network/WebSocketListener.swift:21) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.

Reference code

BrandXAccessory/Network/WebSocketListener.swift:15 — representative boundary

class WebSocketListener {
    // ...
    private var websocketListener: NWListener?
    // ...
}

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
View lifecycle, callbacks, and feature coordination BrandXAccessoryBaseViewController, BrandXAccessoryConfigureViewController, BrandXAccessoryDoneViewController, BrandXAccessorySetupViewController The source’s Controller suffix makes this role explicit.
Receives callback-driven events AccessoryNetworkManagerDelegate, AppDelegate, QRScanningDelegate, SceneDelegate The source’s Delegate suffix makes this role explicit.
Long-lived feature or framework coordination AccessoryNetworkManager, DeviceNetworkManager, LocationManager The source’s Manager suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
View-controller organization BrandXAccessory/UI/ViewControllers/BrandXAccessoryBaseViewController.swift:10 A controller is the verified coordination boundary; this is MVC-style only where a separate model is present.
Protocol-oriented abstraction BrandXAccessory/UI/ViewControllers/BrandXAccessoryConfigureViewController.swift:137 A local protocol and concrete conformance create an explicit capability boundary.
Delegate or data-source callbacks BrandXAccessory/AppDelegate.swift:11 Callback protocols invert event delivery back into the sample’s owner.

Naming conventions

  • Types: Controller: BrandXAccessoryBaseViewController, BrandXAccessoryConfigureViewController, BrandXAccessoryDoneViewController, BrandXAccessorySetupViewController, QRScanningViewController; Delegate: AccessoryNetworkManagerDelegate, AppDelegate, QRScanningDelegate, SceneDelegate, WebSocketConnectionDelegate; Manager: AccessoryNetworkManager, DeviceNetworkManager, LocationManager.
  • Protocols: AccessoryNetworkManagerDelegate, QRScanningDelegate, WebSocketListenerDelegate, WebSocketConnectionDelegate.
  • Methods: applicationShouldTerminateAfterLastWindowClosed, removeConfiguration, applyConfiguration, accessoryNetworkManagerDidUpdate, viewDidLoad, viewWillAppear, viewWillDisappear, viewDidLayoutSubviews.
  • Files: BrandXAccessory/AppDelegate.swift, BrandXAccessorySetup/AppDelegate.swift, BrandXAccessorySetup/Network/AccessoryNetworkManager.swift, BrandXAccessorySetup/UI/ViewControllers/QRScanningViewController.swift, BrandXAccessory/UI/ViewControllers/BrandXAccessoryBaseViewController.swift, BrandXAccessory/UI/ViewControllers/BrandXAccessoryConfigureViewController.swift.

Architecture takeaways

  • AppDelegate is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches UIKit, Cocoa, Network, NetworkExtension 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
BrandXAccessory/AppDelegate.swift AppDelegate
BrandXAccessorySetup/AppDelegate.swift AppDelegate
BrandXAccessorySetup/Network/AccessoryNetworkManager.swift AccessoryNetworkManager, AccessoryNetworkManagerDelegate
BrandXAccessorySetup/UI/ViewControllers/QRScanningViewController.swift QRScanningViewController, QRScanningDelegate
BrandXAccessory/UI/ViewControllers/BrandXAccessoryBaseViewController.swift BrandXAccessoryBaseViewController
BrandXAccessory/UI/ViewControllers/BrandXAccessoryConfigureViewController.swift BrandXAccessoryConfigureViewController
BrandXAccessory/UI/ViewControllers/BrandXAccessoryDoneViewController.swift BrandXAccessoryDoneViewController
BrandXAccessory/UI/ViewControllers/BrandXAccessorySetupViewController.swift BrandXAccessorySetupViewController
BrandXAccessorySetup/Location/LocationManager.swift LocationManager
BrandXAccessorySetup/Network/DeviceNetworkManager.swift DeviceNetworkManager