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

Receiving Voice and Text Communications on a Local Network

At a glance

Item Summary
Purpose Provide voice and text communication on a local network isolated from Apple Push Notification service by adopting Local Push Connectivity.
App architecture A C/Objective-C header, Swift sample with the source-visible chain SimplePushAppDirectoryViewDirectoryViewModelSimplePushProviderNetwork APIs.
Main patterns Model-View-ViewModel, Protocol-oriented abstraction, Delegate or data-source callbacks, Coordinator, SwiftUI environment injection, Publisher-backed observable state
Project style 52 scanned source file(s) across C/Objective-C header, Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: DispatchQueue(label:), DispatchQueue.main, RunLoop; none alone proves a background thread.
State/event model Source-visible mechanisms: AnyCancellable, NotificationCenter, @Published, receive(on:).
Key frameworks/packages Foundation, Combine, SimplePushKit, SwiftUI, Network; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── SimplePush/
│   └── SimplePush/
│       ├── SimplePushApp.swift
│       ├── UI/
│       │   ├── DirectoryViewModel.swift
│       │   ├── SettingsViewModel.swift
│       │   ├── UserViewModel.swift
│       │   ├── MessagingViewModel.swift
│       │   └── AppManager.swift
│       ├── Managers/
│       │   └── CallManager.swift
│       └── AppDelegate.swift
├── SimplePushKit/
│   └── SimplePushKit/
│       └── Networking/
│           ├── RequestResponseSession.swift
│           └── ConnectionOptions.swift
└── SimplePushServer/
    └── SimplePushServer/
        ├── Client.swift
        └── main.swift

Structure observations

  • Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
  • Primary languages: C/Objective-C header, Swift.
  • The verified tree contains 15 project/configuration file(s) and 83 source declaration(s).

Overall architecture

Reference code

SimplePush/SimplePush/SimplePushApp.swift:11 — architecture anchor

@main
struct SimplePushApp: App {
    @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate
    // ...
}

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 Network Extension.

Ownership and state

Ownership evidence

SimplePush/SimplePush/SimplePushApp.swift:13 — stored dependency or nearest verified ownership anchor

@main
struct SimplePushApp: App {
    @UIApplicationDelegateAdaptor private var appDelegate: AppDelegate
    // ...
}
Owner Object or state Relationship Mutation authority
SimplePushApp AppDelegate (appDelegate) stores or receives Owning lexical scope
SimplePushApp RootViewCoordinator (rootViewCoordinator) owns wrapper-managed state Owning lexical scope
DirectoryViewModel State (state) stores or receives App/module collaborators
DirectoryViewModel User (connectedUser) 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. SimplePush/SimplePush/AppDelegate.swift:14
Queue scheduling DispatchQueue.main The source addresses the main dispatch queue. SimplePush/SimplePush/Managers/UserManager.swift:70
Run-loop scheduling RunLoop The source refers to a run loop; the owning thread requires surrounding evidence. SimplePushServer/SimplePushServer/main.swift:20

@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

SimplePush/SimplePush/AppDelegate.swift:14 — representative execution boundary

class AppDelegate: NSObject, UIApplicationDelegate {
    private let dispatchQueue = DispatchQueue(label: "AppDelegate.dispatchQueue")
    // ...
}

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 AnyCancellable A cancellable value records subscription lifetime management. SimplePush/Common/Networking/BaseChannel.swift:32
State propagation NotificationCenter NotificationCenter distributes named process-local events. SimplePush/SimplePush/AppDelegate.swift:70
State propagation @Published A published property can emit owner-controlled changes. SimplePush/SimplePush/Managers/CallManager.swift:41
Combine scheduling receive(on:) receive(on:) selects the scheduler for downstream delivery. SimplePush/SimplePush/Managers/CallManager.swift:74
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. SimplePush/Common/Networking/BaseChannel.swift:8
Source import Combine The cited file imports this module; runtime use and architectural role are not inferred. SimplePush/Common/Networking/BaseChannel.swift:9
Source import SimplePushKit The cited file imports this module; runtime use and architectural role are not inferred. SimplePush/Common/Networking/BaseChannel.swift:11
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. SimplePush/SimplePush/SimplePushApp.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

SimplePushKit/SimplePushKit/Coding/KeyCodable.swift:21 — representative type boundary

protocol KeyCodable {
    associatedtype Key: Hashable
    var keymap: [Key: Codable.Type] { get }
}
Type Responsibility Depends on or conforms to
SimplePushApp Application entry and top-level composition App
DirectoryViewModel UI-facing state and feature coordination ObservableObject
CallManager Long-lived feature or framework coordination NSObject
SettingsViewModel UI-facing state and feature coordination ObservableObject
UserViewModel UI-facing state and feature coordination ObservableObject
PresentedView User-interface presentation and input forwarding Identifiable
RequestResponseSession Owns a session-scoped interaction NetworkSession
Command Represents or runs a user/system command String, Codable
MessagingViewModel UI-facing state and feature coordination ObservableObject
Client External-system or framework client Concrete collaborators/imported frameworks

The source explicitly defines local protocol relationships: InviteRoutable, KeyCoderKeyCodable, TextMessageRoutable, RootViewCoordinatorPresenter, UserViewModelPresenter.

Access control

Symbol Access Verified effect Likely rationale
messagePublisher (SimplePush/Common/Networking/BaseChannel.swift:23) private(set) Read access follows the declaration; writes remain in the private scope. Inference: allow observation while reserving invariant-changing writes for the owner.
statePublisher (SimplePush/Common/Networking/BaseChannel.swift:24) private(set) Read access follows the declaration; writes remain in the private scope. Inference: allow observation while reserving invariant-changing writes for the owner.
networkSession (SimplePush/Common/Networking/BaseChannel.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.
heartbeatMonitor (SimplePush/Common/Networking/BaseChannel.swift:26) 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

SimplePush/Common/Networking/BaseChannel.swift:23 — representative boundary

class BaseChannel {
    // ...
    private(set) lazy var messagePublisher: AnyPublisher<Codable, Never> = internalMessageSubject.dropNil()
    // ...
}

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 SimplePushApp The source’s App suffix makes this role explicit.
External-system or framework client Client The source’s Client suffix makes this role explicit.
Represents or runs a user/system command Command The source’s Command suffix makes this role explicit.
Cross-object flow or session coordination HeartbeatCoordinator, RootViewCoordinator The source’s Coordinator suffix makes this role explicit.
Receives callback-driven events AppDelegate The source’s Delegate suffix makes this role explicit.
Long-lived feature or framework coordination CallManager, MessagingManager, PushConfigurationManager, SettingsManager The source’s Manager suffix makes this role explicit.
Monitors framework or system state HeartbeatMonitor The source’s Monitor suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Model-View-ViewModel SimplePush/SimplePush/UI/DirectoryViewModel.swift:12 Role-named view models keep UI-facing state or coordination outside view declarations.
Protocol-oriented abstraction SimplePushKit/SimplePushKit/Models/Invite.swift:10 A local protocol and concrete conformance create an explicit capability boundary.
Delegate or data-source callbacks SimplePush/SimplePush/AppDelegate.swift:13 Callback protocols invert event delivery back into the sample’s owner.
Coordinator SimplePushKit/SimplePushKit/Networking/HeartbeatCoordinator.swift:11 A role-named coordinator centralizes cross-object flow.
SwiftUI environment injection SimplePush/SimplePush/UI/DirectoryView.swift:14 The environment supplies state or a capability without threading it through every initializer.
Publisher-backed observable state SimplePush/SimplePush/Managers/CallManager.swift:41 Published properties notify observers while mutation remains with the state object.

Naming conventions

  • Types: App: SimplePushApp; Client: Client; Command: Command; Coordinator: HeartbeatCoordinator, RootViewCoordinator; Delegate: AppDelegate; Manager: CallManager, MessagingManager, PushConfigurationManager, SettingsManager, UserManager; Monitor: HeartbeatMonitor; Provider: SimplePushProvider.
  • Protocols: KeyCodable, Routable, Presenter.
  • Methods: view, userView, sendCall, receiveCall, endCall, cleanUpActiveCall, requestCallKitTransaction, updateCallHandle.
  • Files: SimplePush/SimplePush/SimplePushApp.swift, SimplePush/SimplePush/UI/DirectoryViewModel.swift, SimplePush/SimplePush/Managers/CallManager.swift, SimplePush/SimplePush/UI/SettingsViewModel.swift, SimplePush/SimplePush/UI/UserViewModel.swift, SimplePushKit/SimplePushKit/Networking/RequestResponseSession.swift.

Architecture takeaways

  • SimplePushApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SimplePushKit, SwiftUI, Network, UIKit 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
SimplePush/SimplePush/SimplePushApp.swift Cited implementation, SwiftUI, SimplePushApp
SimplePushKit/SimplePushKit/Coding/KeyCodable.swift KeyCodable, KeyCodedPayload, KeyCodableError
SimplePush/Common/Networking/BaseChannel.swift Cited implementation, AnyCancellable, Foundation, Combine, SimplePushKit, BaseChannel, ConnectAction
SimplePush/SimplePush/UI/DirectoryViewModel.swift DirectoryViewModel, State, NetworkConfigurationMode
SimplePushKit/SimplePushKit/Models/Invite.swift Cited implementation, Invite
SimplePush/SimplePush/AppDelegate.swift Cited implementation, DispatchQueue(label:), NotificationCenter, AppDelegate
SimplePushKit/SimplePushKit/Networking/HeartbeatCoordinator.swift HeartbeatCoordinator, Error, When
SimplePush/SimplePush/UI/DirectoryView.swift Cited implementation, DirectoryView
SimplePush/SimplePush/Managers/CallManager.swift Cited implementation, @Published, receive(on:), CallManager, State, InternalCallAction, CallRole, TerminatedReason
SimplePush/SimplePush/Managers/UserManager.swift DispatchQueue.main, UserManager, UserAvailability
SimplePushServer/SimplePushServer/main.swift RunLoop, Feature implementation
SimplePush/SimplePush/UI/SettingsViewModel.swift SettingsViewModel, SettingsGroup
SimplePush/SimplePush/UI/UserViewModel.swift UserViewModel, PresentedView
SimplePushKit/SimplePushKit/Networking/RequestResponseSession.swift RequestResponseSession, Error, PendingRequest, Command, Wrapper
SimplePush/SimplePush/UI/MessagingViewModel.swift MessagingViewModel
SimplePushServer/SimplePushServer/Client.swift Client, State, Connection, Error