One Logo Pool Ball
Network · IOS API REFERENCE

NWBrowser

class · iOS 13.0+ · SDK 27.1

final class NWBrowser

An NWBrowser discovers and tracks changes of advertised services in a local area network. Currently, only Bonjour services are supported. Whenever services become available, get modified, or go away, the browser will generate a set of browse results tracking those changes. The user may subscribe to and receive these updates as long as the browser is active.

Members (13)

get · iOS 13.0+

descriptor

TypeScript
get descriptor(): NWBrowser_Descriptor
Swift declaration
final let descriptor: NWBrowser.Descriptor

The browse descriptor with which the browser was created.

get · iOS 13.0+

parameters

TypeScript
get parameters(): NWParameters
Swift declaration
final let parameters: NWParameters

The parameters with which the browser was created.

get · iOS 13.0+

browseResults

TypeScript
get browseResults(): Array<NWBrowser_Result>
Swift declaration
final var browseResults: Set<NWBrowser.Result> { get }

The set of browse results representing a snapshot of the current services available on the network.

get · iOS 13.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.

get · iOS 13.0+

stateUpdateHandler

TypeScript
get stateUpdateHandler(): (((arg0: NWBrowser_State) => Promise<void>)) | null
Swift declaration
@preconcurrency final var stateUpdateHandler: (@Sendable (NWBrowser.State) -> Void)? { get set }

Set a block to be called when the browser's state changes, which may be called multiple times until the browser is cancelled.

set · iOS 13.0+

stateUpdateHandler

TypeScript
set stateUpdateHandler(value: (((arg0: NWBrowser_State) => void)) | null)
Swift declaration
@preconcurrency final var stateUpdateHandler: (@Sendable (NWBrowser.State) -> Void)? { get set }

Set a block to be called when the browser's state changes, which may be called multiple times until the browser is cancelled.

get · iOS 13.0+

browseResultsChangedHandler

TypeScript
get browseResultsChangedHandler(): (((arg0: Array<NWBrowser_Result>, arg1: Array<NWBrowser_Result_Change>) => Promise<void>)) | null
Swift declaration
@preconcurrency final var browseResultsChangedHandler: (@Sendable (Set<NWBrowser.Result>, Set<NWBrowser.Result.Change>) -> Void)? { get set }

Set a block to be called when the browser's set of browse results has been updated, which may be called multiple times until the browser is cancelled.

set · iOS 13.0+

browseResultsChangedHandler

TypeScript
set browseResultsChangedHandler(value: (((arg0: Array<NWBrowser_Result>, arg1: Array<NWBrowser_Result_Change>) => void)) | null)
Swift declaration
@preconcurrency final var browseResultsChangedHandler: (@Sendable (Set<NWBrowser.Result>, Set<NWBrowser.Result.Change>) -> Void)? { get set }

Set a block to be called when the browser's set of browse results has been updated, which may be called multiple times until the browser is cancelled.

init · iOS 13.0+

init

TypeScript
static init(descriptor: NWBrowser_Descriptor, parameters: NWParameters): NWBrowser
Swift declaration
init(for descriptor: NWBrowser.Descriptor, using parameters: NWParameters)

Create a new browser that will browse for the service specified by a browse descriptor, with parameters. - Parameter descriptor: A browse descriptor describing the kind of service to browse for. - Parameter parameters: The parameters define which protocol and interfaces to use during browsing.

get · iOS 13.0+

queue

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

Get the queue used for delivering block handlers, such as the `stateUpdateHandler` and `browseResultsChangedHandler`. If the browser has not yet been started, the queue will be nil. Once the connection has been started, the queue will be non-nil.

method · iOS 13.0+

start

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

Start the browser and provide a dispatch queue for callback blocks. Starts the browser, which will cause the browser to begin browsing for services on the network. A `stateUpdateHandler` may be used to determine when the state changes. If the browser fails, the state will transition to failed with an associated `NWError` value. Otherwise, the state will transition to ready. `start()` should only be called once on a browser, and multiple calls to `start()` will be ignored. - Parameter queue: The dispatch queue on which browser callbacks will be delivered.

get · iOS 13.0+

state

TypeScript
get state(): NWBrowser_State
Swift declaration
final var state: NWBrowser.State { get }

The current state of the browser.

method · iOS 13.0+

cancel

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

Cancel the browser, and cause all update handlers to be cancelled. `cancel()` is asynchronous. The last callback will be to the `stateUpdateHandler` with the cancelled state. After the cancelled state is delivered, all blocks are released to break retain cycles. Calls to `cancel()` after the first one are ignored. The browser cannot be restarted after it has been cancelled.

Skipped declarations

No declarations were skipped in this snapshot.

All Network types →