Documentation / 07
Adopting SwiftPods
Bring an existing Xcode project's dependencies, settings and build scripts into a declarative Podfile.
Steps
- Save the current project in version control. Inventory its packages, prebuilt SDKs, target settings and build scripts. If another tool generated the integration, remove it first as that tool describes;
swiftpods helplists the cleanup options ofswiftpods deintegrate. - Create a Podfile using the declarations below; run
swiftpods checkuntil it passes. - Run
swiftpods install --resolve. To take ownership of matching package references already in Xcode, explicitly add--adopt. - Review the project diff, build, then commit the Podfile, the project,
Package.resolvedand, if installation wrote one,SwiftPods.lock.
Declarations
| Remote Swift package | spm 'https://…/Package.git', '1.2.0', products: ['Product']. |
|---|---|
| Local Swift package | spm 'Local', path: 'Modules/Local'. |
| Prebuilt SDK | binary with a local path or an HTTPS archive and SHA-256. |
| Shared dependencies | group :name do … end, use :name and include 'file.podfile'. |
| Target build settings | settings 'KEY' => 'value', optionally scoped to configurations. |
| Build-time scripts | script_phase with declared inputs and outputs. |
| Shared deployment target | A platform line in an included file. |
Example
A game target links Alamofire, added in Xcode, sets -ObjC in its build settings and repeats the ad SDK list of a sibling project. Its Podfile:
platform :ios, '15.4'
include '../Shared/AppLovin.podfile'
target 'Game' do
use :applovin_max
spm 'https://github.com/Alamofire/Alamofire.git', '~> 5.9'
settings 'OTHER_LDFLAGS' => '$(inherited) -ObjC'
endThe shared group replaces the copied SDK list, and swiftpods install --resolve --adopt takes over the Alamofire reference. Then delete OTHER_LDFLAGS from the target's build settings: settings stored on the target win over the Podfile's.