skip to content

As iOS lead for an app with fifteen SwiftPM dependencies, what policy would you set for Package.resolved, update cadence, branch pins and where packages are fetched from?

level: principalimportance: should knowfreq 35%

answer

  1. the file is the contract
  2. CI must refuse stale pins
  3. small updates, on a schedule
  4. no unversioned pins on release
  5. registries, mirrors and fingerprints

basics

~20 s

Commit Package.resolved and make CI refuse a stale one; take updates as small reviewed pull requests on a schedule, with security fixes out of band; ban branch and revision pins from release builds; decide deliberately between Git URLs, mirrors and a private registry.

solid answer

~50 s

I would make `Package.resolved` the contract: committed, changed only by `swift package update` in a reviewed pull request, and enforced by CI with `--force-resolved-versions` or `xcodebuild -onlyUsePackageVersionsFromResolvedFile`. Requirements default to `from:`, with `.upToNextMinor(from:)` for 0.x packages, and `exact:` only with a comment saying why and when it goes. Branch and revision pins may live on feature branches but block a release. Updates run on a fixed cadence, every sprint or two, as small pull requests built from `swift package update --dry-run`, one package at a time for risky ones, with security releases taken immediately. An owner rotates through that work. Finally, decide where packages come from: Git URLs are simplest, `swift package config set-mirror` redirects them to internal copies, and a private registry (tools version 5.7+) adds `scope.name` identities, signing and checksum fingerprints at the cost of running one.

code

bash · 11 lines
bash
# CI: build exactly what Package.resolved records
swift build --force-resolved-versions
xcodebuild -resolvePackageDependencies -onlyUsePackageVersionsFromResolvedFile -scheme Shop

# Scheduled update pull request
swift package update --dry-run
swift package update networking analytics-sdk

# Fetch through an internal mirror or a private registry
swift package config set-mirror --original https://example.com/vendor/analytics-sdk.git --mirror https://git.internal.example/mirrors/analytics-sdk.git
swift package-registry set https://packages.internal.example

go deeper

for a junior

Recall the basics behind the policy: commit Package.resolved, and only change versions on purpose with swift package update.

for a middle

Explain which requirement form fits which dependency, and how CI is made to fail when Package.resolved is out of date.

for a senior

Show the operational side: scheduled small updates, out-of-band security fixes, clean rollbacks, and catching branch pins before release.

for a principal

Weigh stability against staleness and cost: update cadence and ownership, when exceptions are allowed, and whether a mirror or private registry earns its upkeep.

## The decisions a lead owns With fifteen direct dependencies, and often several times that many transitive ones, dependency management is no longer something each developer does when convenient. Swift Package Manager supplies the mechanisms; the lead decides how the team uses them. Four decisions matter: - **what is reproducible**: who may change `Package.resolved`, and how CI enforces it; - **how requirements are written**: ranges, pins and unversioned requirements; - **when updates happen and who does them**; - **where packages come from**: Git hosts, mirrors or a registry. None has a single right answer; each trades stability against staleness and effort. ## Reproducibility: the file is the contract `Package.resolved` records the exact version and commit of every package in the graph, and SwiftPM reuses it for the top-level package. For an app, the policy is straightforward: 1. Commit the file; for an Xcode app it lives inside the `.xcodeproj` or `.xcworkspace`. 2. Make CI refuse a stale file: `swift build --force-resolved-versions` for packages, `xcodebuild -onlyUsePackageVersionsFromResolvedFile` for Xcode projects. A requirement changed without new pins then fails instead of silently resolving something nobody reviewed. 3. Treat every `Package.resolved` diff as a code change: it names exactly which third-party code you are about to ship. ## Requirement style | Requirement | Team rule | Reason | |---|---|---| | `from:` | default | allows fixes and compatible features; stops below the next major | | `.upToNextMinor(from:)` | 0.x packages, or a dependency with a history of minor-release breakage | `from: "0.4.0"` would otherwise accept anything below 1.0.0 | | `exact:` | allowed with a comment and an end date | the documentation warns exact pins cause graph conflicts | | `branch:` / `revision:` | feature branches only, blocked on release | unversioned code; a package using them cannot be depended on by version | The branch rule deserves enforcement, for example a CI check that rejects `branch:` and `revision:` in manifests on the release branch. A branch pin is reproducible only through its recorded commit, and the next `swift package update` moves it to whatever the branch holds then. ## Update cadence and ownership The tradeoff is between small, frequent updates and rare, painful ones: - **Scheduled updates**, every sprint or every two weeks: run `swift package update --dry-run`, update in small groups or one package at a time for risky dependencies, read the release notes, run the full test suite, and merge the `Package.resolved` diff. - **Out-of-band updates** for security fixes, using `swift package update <name>` on that one package. - **Rollback** with `swift package resolve <name> --version <previous>` rather than hand-edited JSON. - **Ownership**: a rotating owner or a platform team; without one, updates stop and the graph drifts until a forced major upgrade arrives as a single large change. Regular updates also make version conflicts rarer, because the app never falls several majors behind a shared package. ## Where packages come from - **Git URLs** are the default and need nothing new. SwiftPM records a trust-on-first-use **fingerprint**, the Git hash of the revision, for each downloaded version and warns or errors when a later download of that version differs, which is how a re-pointed tag shows up. - **Mirrors**: `swift package config set-mirror --original <url> --mirror <url>` redirects a dependency to an internal copy without editing manifests, which helps when the public host is unreachable from CI. - **A private registry** (SE-0292): manifests use `.package(id: "scope.name", from: "1.0.0")`, available from tools version 5.7. `swift package-registry set` writes the project's `.swiftpm/configuration/registries.json`, `swift package-registry login` stores credentials, and the registry serves source archives whose checksums SwiftPM fingerprints. Signed releases are validated according to `registries.json`; by default `onUnsigned` and `onUntrustedCertificate` are set to `prompt`. The cost is running the service and publishing to it. A graph that mixes both origins needs one more rule. SwiftPM treats `mona.LinkedList` from a registry and the same package from its Git URL as different packages, which leads to symbol clashes. `--use-registry-identity-for-scm`, or `xcodebuild -packageDependencySCMToRegistryTransformation useRegistryIdentity`, makes SwiftPM look up Git URLs in the registry and deduplicate them. ## Writing it down A one-page policy should state the requirement rules, the CI flags, the update cadence and owner, the rollback command, and the fetch source, plus the exception process: who may approve an `exact:` or branch pin, and when it is reviewed again. That page is what a new engineer reads before their first `swift package update`.

  • Would you ever allow a branch pin on the main branch?
    Briefly, for a fix the team needs before upstream tags it, and only pinned to a fork with the commit recorded in `Package.resolved`. It carries an owner and a removal trigger, the upstream tag, and the release check still blocks it from shipping unless the lead signs off. Anything longer-lived should become a tagged release of the fork, so the requirement is versioned again.
  • What does a private registry give you that Git URLs plus a committed Package.resolved do not?
    Stable `scope.name` identities independent of where code is hosted, source archives with checksums that SwiftPM fingerprints, and optional publisher signing that SwiftPM validates under the `registries.json` security settings. A committed `Package.resolved` already gives reproducibility with Git URLs, so the registry is about provenance and control, paid for by running the service and publishing to it.

  • Package.resolved causes merge conflicts, so the app should not commit it.
  • Updating every dependency once a year in one big change is the least risky approach.
  • Branch pins are fine in release builds because Package.resolved records the commit anyway.
  • exact: pins on every dependency are the best way to make builds reproducible.
  • A private registry is required before SwiftPM builds can be reproducible.

Assumes swift-tools-version 5.7 or later for registry dependencies declared with .package(id:from:), checked against SwiftPM 6.4; Git-URL requirements and Package.resolved work on every supported tools version.