there was a pitch to move URLSession and some related types to a new module some time ago. We have been working on implementing it, and a patch is now available in the swift-corelibs-foundation repository.
I want to spend a moment addressing the original feedback on the proposal. There are a number of places in
clang and the Swift compiler where the name of the Foundation module is hardcoded. That is unfortunate; it made the consequences of moving relevant Foundation types into a "base" module widespread. We did some exploratory work to address these issues, but found that this greatly complicated some very performance-sensitive sections of the infrastructure that special-case Foundation, such as ObjC bridging.
In the end, we choose the simpler approach of just providing a separate module that will require an additional
import line — the patch adds diagnostics, so that people using affected types with 5.1 will receive a clear message at compile time detailing what to do.
Wait, what does 'an additional import line' mean?
If you use one of the affected types, you can make the source file compatible with both Darwin and Linux by adding:
#if canImport(FoundationNetworking) import FoundationNetworking #endif
at the top. You don't have to guess which files, though; when compiling using Swift 5.1, the compiler will notice when you need the new line and tell you with a message like:
/YourApp/SourceFile.swift:510:13: error: 'URLSession' has been renamed to 'FoundationNetworking.URLSession': This type has moved to the FoundationNetworking module. Import that module to use it.
I wanted to hear from you — is this going to affect your project, and to what degree?