One Logo Pool Ball
Network · IOS API REFERENCE

NWPathMonitor

class · iOS 12.0+ · SDK 27.1

final class NWPathMonitor

The NWPathMonitor allows the caller to fetch the current global path (or a path restricted to a specific network interface type). The path for the monitor is an observable property that will be updated upon each network change. Paths generated by a path monitor are not specific to a given endpoint, and will not have the localEndpoint or remoteEndpoint properties set. The paths will watch the state of multiple interfaces, and allows the application to enumerate the available interfaces for use in creating connections or listeners bound to specific interfaces.

Members (12)

get · iOS 12.0+

currentPath

TypeScript
get currentPath(): NWPath
Swift declaration
final var currentPath: NWPath { get set }

Access the current network path tracked by the monitor

set · iOS 12.0+

currentPath

TypeScript
set currentPath(value: NWPath)
Swift declaration
final var currentPath: NWPath { get set }

Access the current network path tracked by the monitor

get · iOS 17.0+

debugDescription

TypeScript
get debugDescription(): string
Swift declaration
final var debugDescription: String { get }

A textual representation of this instance, suitable for debugging. Calling this property directly is discouraged. Instead, convert an instance of any type to a string by using the `String(reflecting:)` initializer. This initializer works with any type, and uses the custom `debugDescription` property for types that conform to `CustomDebugStringConvertible`: struct Point: CustomDebugStringConvertible { let x: Int, y: Int var debugDescription: String { return "(\(x), \(y))" } } let p = Point(x: 21, y: 30) let s = String(reflecting: p) print(s) // Prints "(21, 30)" The conversion of `p` to a string in the assignment to `s` uses the `Point` type's `debugDescription` property.

method · iOS 17.0+

makeAsyncIterator

TypeScript
makeAsyncIterator(): NWPathMonitor_Iterator
Swift declaration
final func makeAsyncIterator() -> NWPathMonitor.Iterator

Creates the asynchronous iterator that produces elements of this asynchronous sequence. - Returns: An instance of the `AsyncIterator` type used to produce elements of the asynchronous sequence.

get · iOS 12.0+

pathUpdateHandler

TypeScript
get pathUpdateHandler(): (((arg0: NWPath) => Promise<void>)) | null
Swift declaration
@preconcurrency final var pathUpdateHandler: (@Sendable (NWPath) -> Void)? { get set }

Set a block to be called when the network path changes. pathUpdateHandler will not be called until `start` is called.

set · iOS 12.0+

pathUpdateHandler

TypeScript
set pathUpdateHandler(value: (((arg0: NWPath) => void)) | null)
Swift declaration
@preconcurrency final var pathUpdateHandler: (@Sendable (NWPath) -> Void)? { get set }

Set a block to be called when the network path changes. pathUpdateHandler will not be called until `start` is called.

init · iOS 12.0+

init

TypeScript
static initRequiredInterfaceType(requiredInterfaceType: NWInterface_InterfaceType): NWPathMonitor
Swift declaration
init(requiredInterfaceType: NWInterface.InterfaceType)

Create a network path monitor that watches a single interface type.

init · iOS 14.0+

init

TypeScript
static initProhibitedInterfaceTypes(prohibitedInterfaceTypes: Array<NWInterface_InterfaceType>): NWPathMonitor
Swift declaration
init(prohibitedInterfaceTypes: [NWInterface.InterfaceType])

Create a network path monitor that prohibits an array of interface types.

get · iOS 12.0+

queue

TypeScript
get queue(): (_Dispatch_DispatchQueue) | null
Swift declaration
final var queue: DispatchQueue? { get }

Get queue used for delivering the pathUpdateHandler block. If the path monitor has not yet been started, the queue will be nil. Once the path monitor has been started, the queue will be non-nil.

method · iOS 12.0+

start

TypeScript
start(queue: _Dispatch_DispatchQueue): void
Swift declaration
final func start(queue: DispatchQueue)

Start the path monitor and set a queue on which path updates will be delivered. Start should only be called once on a monitor, and multiple calls to start will be ignored. Once started, the path monitor must be explicitly cancelled when it is no longer needed.

method · iOS 12.0+

cancel

TypeScript
cancel(): void
Swift declaration
final func cancel()

Cancel the path monitor, after which point no more path updates will be delivered.

init · iOS 12.0+

init

TypeScript
static init(): NWPathMonitor
Swift declaration
init()

Create a network path monitor to monitor overall network state for the system and to enumerate all interfaces that are available for general use by applications.

Skipped declarations

No declarations were skipped in this snapshot.

All Network types →