Documentation / 07

Adopting SwiftPods

Bring an existing Xcode project's dependencies, settings and build scripts into a declarative Podfile.

Steps

  1. 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 help lists the cleanup options of swiftpods deintegrate.
  2. Create a Podfile using the declarations below; run swiftpods check until it passes.
  3. Run swiftpods install --resolve. To take ownership of matching package references already in Xcode, explicitly add --adopt.
  4. Review the project diff, build, then commit the Podfile, the project, Package.resolved and, if installation wrote one, SwiftPods.lock.

Declarations

Remote Swift packagespm 'https://…/Package.git', '1.2.0', products: ['Product'].
Local Swift packagespm 'Local', path: 'Modules/Local'.
Prebuilt SDKbinary with a local path or an HTTPS archive and SHA-256.
Shared dependenciesgroup :name do … end, use :name and include 'file.podfile'.
Target build settingssettings 'KEY' => 'value', optionally scoped to configurations.
Build-time scriptsscript_phase with declared inputs and outputs.
Shared deployment targetA 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'
end

The 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.