The documentation is pretty much blank. The same thing applies to the root NetworkProtocolOptions protocol. What are ContentType, LegacyMessage, BelowProtocol, Metadata, and ProtocolStorage? I can't determine if I should use these or not.
You’ve asked questions about a bunch of different protocols, and they all have the same general answer: These protocols exist to support the desired features of the new Network framework API.
Let’s take at BelowProtocol as a specific example. It’s an associated type on NetworkProtocolOptions. When a type conforms to NetworkProtocolOptions, it tells the compiler which type is ‘below’ this type in the protocol stack. For example, the TLS struct conforms to StreamProtocol which in turns conforms to NetworkProtocolOptions. TLS sets its BelowProtocol to TCP, indicating that TLS has to be layered on top of TCP. So, you can write code like this:
let connection = NetworkConnection(to: endpoint) {
TLS {
TCP()
}
}
but if do this you get an error:
let connection = NetworkConnection(to: endpoint) {
TLS {
UDP()
// ^ Cannot convert value of type 'UDP' to expected argument type 'TCP'
}
}
The above means that this question:
I can't determine if I should use these or not.
is hard to answer because it depends on your perspective:
- Anyone using the new Network framework API ends up using these protocols implicitly.
- But you don’t need to use them explicitly unless you’re doing something weird.
That leaves you with two options:
- You can try using the API and see if you ever need to touch these protocols and then, if so, puzzle out the specifics of that protocol.
- Or if you want work out how this stuff works under the covers, you can open the ‘header’ file [1] and go for a rummage.
Honestly, I think the first choice is the better one. And there’s a bunch of help available:
- WWDC 2025 Session 250 Use structured concurrency with Network framework is a great introduction to the API as a whole.
- TN3213 Moving from Multipeer Connectivity to Network framework has lots of specific examples.
- There’s more stuff linked to in Networking Resources.
And if you get stuck, I’m happy to answer follow-up questions here.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] While Swift doesn't have headers per se, the Swift interface to Network framework is available in text form at Network.framework/Modules/Network.swiftmodule/arm64e-apple-ios.swiftinterface.