Documentation / Swift Package Manager
Swift packages
Use spm to declare Swift Package Manager dependencies alongside pods. Keep both kinds of dependencies in the same Podfile and connect their products to the same Xcode target.
Add a package to a target
platform :ios, '15.0'
target 'MyApp' do
pod 'Networking', :path => './Modules/Networking'
spm 'swift-collections',
:git => 'https://github.com/apple/swift-collections.git',
:from => '1.0.0',
:products => ['Collections']
endgit identifies the package repository. products lists the products to link to this target; use the names declared in the package's Package.swift. This example selects Collections from Swift Collections.
Choose a version requirement
Specify exactly one requirement per package:
| Option | Meaning |
|---|---|
:from => '1.0.0' | Allow versions starting at 1.0.0, below the next major version. |
:exact => '1.0.0' | Select one release version. |
:range => ['1.0.0', '2.0.0'] | Use a minimum version and an exclusive upper bound. |
:branch => 'main' | Track a Git branch. |
:revision => 'COMMIT_SHA' | Select a full Git commit; replace the placeholder with its actual SHA. |
Select products
A package can publish several products. Select only the ones needed by the target:
spm 'swift-collections',
:git => 'https://github.com/apple/swift-collections.git',
:from => '1.0.0',
:products => ['DequeModule', 'OrderedCollections']Place spm inside a concrete target or an abstract_target shared by several targets. Declare each SDK once; SwiftPods reports known module conflicts between pod and package dependencies.
Install and build
swiftpods install
open MyApp.xcworkspaceSwiftPods installs pods and adds native Swift package and product references to the Xcode project. Xcode resolves and builds the Swift packages. Existing package references and Package.resolved are preserved.
Versions in your team and CI
Commit Podfile, Podfile.lock and the Xcode project's Package.resolved. The pod lockfile records pod versions; Package.resolved records Swift package versions.
swiftpods install --deployment
xcodebuild -resolvePackageDependencies \
-workspace MyApp.xcworkspace -scheme MyApp \
-onlyUsePackageVersionsFromResolvedFile--deployment enforces the pod lockfile. The Xcode flag keeps Swift packages at the versions recorded in Package.resolved. Use your workspace and shared scheme names in the command above.