Search code examples
swiftxcodeswift-package-manager

Is there the need for both package.swift and package.resolved?


I'm new to Swift Package Manager but I pulled a project from git with different people working on it and I can't find the package.swift in it. On a further check, I realized package.resolved was in there.

  1. Do the two perform the same role?
  2. When I build, I don't see a Sources folder, Even though I see the Packages in Xcode. Is that normal?
  3. New sub packages eg. (FirebaseAuth from Firebase) that I now add to the dependencies are not available for use in the project. Seeing "No such module" errors

Solution

  • For the first question:

    It's like Podfile & Podfile.lock for instance (and many other dependency managers).

    The Package.swift let you tell what you need.
    The Package.resolved let you know what was downloaded/used.

    The Package.swift is the "command", "developer settings", in this case it's "Swift code", and the other one is just a "text file", a manifest, a written record of what is really used.

    In the Package.swift you might need a PackageA. But PackageA might need SubpackageB. But it would be a pain to add manually all the subpackages. At a higher level, you don't need to know them.
    In the Package.resolved there are written there.

    You might specify a version, or a minimum version for a Package: like "1.0.0" up to "1.xx.xx", to get the fixes/revisions when updating the dependencies.
    In the Package.resolved you have the exact versions that have been downloaded/used.
    This allow you, if you don't do an update, to recover the exact same version of the packages.
    For instance, if you have the "1.0.0", there is a "1.1.0" available that fix an issue, you might want to be on that specific version "1.0.0" to reproduce the issue, or if the "1.1.0" introduces a new bug, you want to keep that 1.1.0, and not perform an update until otherwise. And when you buil to release the App, you keep using the same version of the packages, the one you used/tested with (until there is a manual update).