Documentation / 03
Swift packages
Use spm to add a Swift package to a target and choose the products it links.
Declare a package
target 'MyApp' do
spm 'https://github.com/Alamofire/Alamofire.git', '~> 5.9'
spm 'Firebase', git: 'https://github.com/firebase/firebase-ios-sdk.git', exact: '13.0.1',
products: %w[FirebaseCore FirebaseAnalytics]
spm 'Networking', path: 'Modules/Networking'
endThe first argument is a name or a Git URL; a URL's last path component, without .git, becomes the name. products defaults to that name. A path declares a local package relative to the Podfile.
Packages by name
Well-known packages can be named without their repository. SwiftPods looks the name up in the public catalog, which supplies the repository and default products:
spm 'Datadog', '~> 3.15'
spm 'Firebase', '~> 13.0', products: %w[FirebaseCore FirebaseAnalytics]Entries hold no versions: the Podfile gives the version, and Swift Package Manager finds it among the package's tags. source lines replace the public catalog with your team's catalogs, searched in order; list the public one too to keep it. Installation reuses the catalog commits recorded in SwiftPods.lock; swiftpods install --update-sources refreshes them.
A source pinned with revision: takes a complete 40-character SHA-1 or 64-character SHA-256 commit ID; short hashes are rejected. Remote catalogs use HTTPS or SSH and must resolve to public IP addresses; for an internal server, use a trusted local mirror via an absolute path or file:// URL. See lock behavior.
Version requirements
A remote package needs exactly one requirement:
'1.2.3', exact: '1.2.3' | Exactly 1.2.3 |
|---|---|
'~> 1.2', from: '1.2.0' | 1.2.0 up to the next major version |
'~> 1.2.3', up_to_next_minor: '1.2.3' | 1.2.3 up to the next minor version |
'>= 1.2', '< 2.0', range: ['1.2', '2.0'] | From 1.2.0, below 2.0.0 |
branch: 'main', revision: '<full commit object ID>' | A branch or a complete 40- or 64-character commit ID |
Versions have at most three numeric components, except for the vendor formats below. A lower bound without an upper bound is rejected rather than guessed.
Some vendors tag packages in their own format. AppLovin publishes MAX adapter 13.9.0.0 as package version 13090000.0.0; the catalog marks such packages, so the Podfile keeps the vendor's version and SwiftPods converts it, ranges included:
spm 'AppLovinMediationGoogleAdapter', '13.9.0.0'
spm 'AppLovinMediationBidMachineAdapter', '~> 3.8.0.0.0'Compile-only packages
link: false builds the package and makes its modules and public headers available to the target, without linking or archiving the SDK's object files into it. Use it for a static plugin when the application owns the SDK's final linkage:
target 'App' do
spm 'SharedSDK', path: 'Modules/SharedSDK'
end
target 'AnalyticsPlugin' do
spm 'SharedSDK', path: 'Modules/SharedSDK', link: false
endThe application declares every SDK product it links, and other static plugins that share the SDK also use link: false. The plugin can import Swift modules, Clang modules, Objective-C interfaces generated from Swift, and public headers of the product's transitive dependencies. Keep $(inherited) when you override compiler flags, header or framework search paths in the Xcode target. Objective-C++ code that uses @import also needs Clang C++ modules, for example OTHER_CPLUSPLUSFLAGS = $(inherited) -fmodules -fcxx-modules.
When a target declares the same product more than once, through groups or inheritance included, the linked declaration wins. A nested target cannot undo an inherited linked declaration with link: false: use inherit! :none and declare its dependencies explicitly, or share the compile-only declarations and add the linked one in the application.
Package identity
Package identity comes from the repository or local directory name, normalized to lowercase and without a trailing .git. Conflicting repository locations with the same identity are rejected.
Package.resolved and CI
swiftpods install --resolve asks Xcode to resolve versions and checks the resulting Package.resolved against the Podfile. An exact requirement such as '18.1.1' remains exact; a stale pin at another version is not accepted as satisfying it.
In CI, swiftpods install --deployment checks the pins without updating them; see locks and deployment.
Packages added in Xcode
SwiftPods leaves package references added in Xcode alone. If the Podfile declares a package the project already references, installation stops; swiftpods install --adopt explicitly transfers that reference to SwiftPods management.