Why do we need an external dependency declaration for Collections?

If we want to import Foundation or Observation we just

  • type import Foundation or import Observation in our source code
  • compile

and everything just works. But if we want to import Collections or OrderedCollections we need to first add a dependancy to our module:

.package(
   url: "https://github.com/apple/swift-collections.git", 
   .upToNextMinor(from: "1.1.0") // or `.upToNextMajor
)

When we look at the above graph about the Foundation framework we see that swift Collections is actually already a dependancy of Foundation. So why is it that we need to explicitly add a dependency for Collections but not for Foundation?

1 Like

On Darwin, Foundation and Observation are delivered by the operating system/SDK, but Collections is not. It’s not even clear that Foundation depends on Collections when building for Darwin.

Darwin Foundation does depend on Collections, but the copy that's distributed with the OS is effectively private and renamed CollectionsInternal so that it doesn't cause symbol collisions for anyone using the package dependency while also linking to Foundation (since the latter group is approximately everyone).

4 Likes