<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Network",
  "identifier" : "/documentation/Network/NetworkConnection/onBetterPathUpdate(_:)-2h2wu",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Network"
    ],
    "preciseIdentifier" : "s:7Network0A10ConnectionCA2A17MultiplexProtocolRzrlE18onBetterPathUpdateyACyxGXDyAF_SbtYbYAcF"
  },
  "title" : "onBetterPathUpdate(_:)"
}
-->

# onBetterPathUpdate(_:)

A better path being available indicates that the system thinks there is a preferred path or
interface to use, compared to the one this connection is actively using. As an example, the
connection is established over an expensive cellular interface and an unmetered Wi-Fi interface
is now available.

```
@discardableResult final func onBetterPathUpdate(_ handler: @escaping @isolated(any) @Sendable (NetworkConnection<ApplicationProtocol>, Bool) -> Void) -> Self
```

## Discussion

Set a closure to be called when a better path becomes available or unavailable, which may be called
multiple times until the connection is cancelled.

When a better path is available, if it is possible to migrate work from this connection to a new connection,
create a new connection to the endpoint. Continue doing work on this connection until the new connection is
ready. Once ready, transition work to the new connection and cancel this one.

This closure will inherit the isolation domain of the caller.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)