The Network framework provides implementations of transport protocols, such as QUIC, along with types used to communicate network endpoints (like IP addresses) and various parameters and preferences for how to set up transport connections.
This package provides access to the implementations of core networking objects and protocol stack architecture from Network.framework that is available on Apple platforms. This package is intended to be used by cross-platform projects like SwiftNIO to be able to access a Swift-based implementation of protocols like QUIC.
On macOS, iOS, and other Apple platforms, apps should use the Network.framework that comes with the operating system.
Note
At this time, all types exposed in this package are marked as SPI and subject to change at any time. There are no support guarantees that can be made until these SPIs transition to stable APIs at a later date.
- Swift 6.3 and up
- macOS 26.0 and up or Linux (Ubuntu 22.04+)
- Xcode 26.0 and up (Apple platforms only)
To build via the command line (for all platforms), run at the root of package:
swift build
To run all unit tests, run:
swift test
Unit tests can also be run by filtering a specific class or function:
% swift test --filter SwiftNetworkUDPTests
% swift test --filter SwiftNetworkUDPTests.testUDPEcho
All unit tests are run automatically upon creation or update of a Pull Request. See CONTRIBUTING for details.
By default, Swift Network will emit logs at debug, info, notice, error, and fault levels. There are also datapath-specific debug logs, referred to as datapath logs, that are disabled by default.
Logging configuration is exposed via package traits:
| Trait | Default | Effect |
|---|---|---|
DisableDebugLogging |
not specified | When specified, compiles out the debug and info logging levels. |
DisableErrorLogging |
not specified | When specified, compiles out the error, notice, and fault logging levels. |
DatapathLogging |
not specified | When specified, compiles in the verbose datapath logging level. Has no effect if DisableDebugLogging is also specified. |
The level traits are expressed as suppression flags so that they compose well across a dependency graph. SwiftPM unifies trait selections by union, so a leaf package can always specify a *Disabled trait to suppress a level that an intermediate left compiled in, but cannot re-introduce a level that an intermediate suppressed.
Intermediate libraries that depend on Swift Network should therefore not modify the default trait set when declaring the dependency. Specifying DisableDebugLogging or DisableErrorLogging in a library's Package.swift would force the corresponding levels to be suppressed for every leaf application that consumes the library, regardless of what those leaves want. The choice belongs to the leaf, where the deployment context is known.
A dependent package opts in to suppression when declaring the dependency, e.g. to compile out all logging:
.package(
url: "https://github.com/apple/swift-network-evolution",
branch: "main",
traits: ["DisableDebugLogging", "DisableErrorLogging"]
)When building this package directly, the swift CLI accepts the same traits:
swift test --traits DisableDebugLogging,DisableErrorLogging
QUIC log output in the qlog format is controlled by the QlogOutput trait, and os_signpost output by SignpostOutput. Both are positive traits and neither is in the default trait set, so qlog and signpost code is compiled out by default.
Either feature is enabled by specifying the trait when declaring the dependency:
.package(
url: "https://github.com/apple/swift-network-evolution",
branch: "main",
traits: ["QlogOutput", "SignpostOutput"]
)For builds driven by Xcode rather than SwiftPM, add the equivalent compilation condition to the relevant xcconfig:
OTHER_SWIFT_FLAGS = $(inherited) -DQlogOutput -DSignpostOutput
When building or running this package directly from the swift CLI, the same trait names are accepted via --traits:
swift build --traits QlogOutput,SignpostOutput
swift test --traits QlogOutput
swift run --traits QlogOutput QUICHandshake
Trait composition is by union across the dependency graph, so once any package in the chain enables QlogOutput or SignpostOutput, every other package consuming Swift Network through that graph will also be built with the trait specified. A leaf package cannot suppress qlog or signpost output that an intermediate dependency turned on.
Intermediate libraries should not specify QlogOutput or SignpostOutput on their Swift Network dependency. These are diagnostic features which incur a performance cost; the decision to enable them belongs to the leaf or to test and benchmark targets that need the output.
This package builds several tools that can be used for benchmarking performance.
IPUDPTransfermeasures processing UDP/IP packets through the stack, for packet/second metrics.QUICHandshakemeasures parallel QUIC handshakes, for handshake/second metrics.QUICStreamLoadmeasures parallel data transfers over parallel QUIC streams, for requests/second metrics.QUICTransfermeasures large data transfers over single QUIC streams, for throughput metrics.
The Swift Network Contributing Guide includes detailed information about participating in the project.
We welcome the following contributions:
- Reporting bugs with clear, reproducible steps via GitHub Issues
- Improving documentation to make the project more accessible
- Adding or enhancing tests to improve reliability and coverage
- Adding ports to new platforms
- Triaging issues by providing feedback, testing, and validation
- Participating in the Networking category on the Swift Forums
Swift Network has a limited scope and is focused on supporting specific projects, such as QUIC in SwiftNIO. Please start with an Issue before opening a Pull Request that adds new functionality or expands the surface.