Network Framework

I've just watched Scott Herschel's WWDC 25 session "Use structured concurrency with Network framework" and I am more than overjoyed to see said framework offer these new features.

However, the documentation has not yet been updated (or it's not where I expect to find it) .. Is there more that I can read about the enhancements to the framework?

One specific question is whether the structured concurrency portion of the framework's enhancement is backward compatible to before "26"?

Answered by Frameworks Engineer in 842752022

You're correct, today those capabilities aren't available before version 26, but could you please file a feedback in Feedback Assistant mentioning that it would be helpful for you?

As often happens, writing a question drove me to find my own answer. In this case, I wrote a sample using the new class "NetworkConnection" and (a) the documentation shows up in Xcode and (b) the new capabilities are not available before xOS 26.

You're correct, today those capabilities aren't available before version 26, but could you please file a feedback in Feedback Assistant mentioning that it would be helpful for you?

To be honest, what I (and others) have wanted is concurrency in NWConnection I've provided that for myself, with suggestions from this Forum, with the following:

extension NWConnection {

    func asyncSend(data: Data?) async throws {
        try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
            send(content: data, completion: .contentProcessed { error in
                if let error {
                    continuation.resume(throwing: error)
                } else {
                    continuation.resume(returning: ())
                }
            })
        }
    }

    func asyncReceive(length: Int) async throws -> Data {
        try await withCheckedThrowingContinuation { continuation in
            receive(minimumIncompleteLength: length, maximumLength: length) { data, _, connectionEnded, error in
                if connectionEnded {
                    logger.log("←→ connection did end")
                    continuation.resume(throwing: NWError.posix(.ECONNRESET))
                } else if let error {
                    continuation.resume(throwing: error)
                } else {
                    continuation.resume(returning: data ?? Data(repeating: 0, count: 4))
                }
            }
        }
    }

}

The significantly increased power and sophistication in NetworkConnection is welcome but my app's networking (with the above Extension) works from Monterey onwards.

I will file a request in Feedback Assistant .. in fact, I'll file two! One to enhance NWConnection to support async and the other to have NetworkConnection operate in current, and older, systems.

[ FB17963806 ]

Network Framework
 
 
Q