Documentation / 02
Podfile
The Podfile is a Ruby-like DSL for dependencies, build settings and script phases. SwiftPods reads its declarations as data.
Syntax
Statements are a name followed by arguments, optionally with a do … end block. Values are strings ('…', or "…" without interpolation), symbols, numbers, true, false, arrays ([…], %w[…], %i[…]) and hashes (key: value, :key => value, 'KEY' => value). Parentheses are optional and # starts a comment. A statement continues on the next line after a comma, an opening bracket, => or \.
Variables, methods, conditionals, require and string interpolation are rejected with a hint. Share declarations with groups and includes instead.
Top level
platform :ios, '15.0' | Default platform and deployment target: ios, macos, tvos, watchos or visionos. |
|---|---|
project 'App.xcodeproj' | Default project, using a relative path inside the Podfile directory. Otherwise, the only project next to the Podfile. |
source 'https://…/catalog.git' | A catalog that resolves package names. Without any, the public catalog. revision: '…' with a complete commit ID pins it. |
include 'shared.podfile' | Reads platform, groups and includes from another file, relative to the including file. |
group :name do … end | Named declarations that targets use, optionally with parameters. |
target 'Name' do … end | An existing Xcode target. |
abstract_target 'Name' do … end | Declarations shared by the targets nested in it. |
Inside a target
spm | A Swift package and the products the target links. |
|---|---|
binary | A prebuilt SDK. |
use :a, :b | Applies groups. |
use :a, flag: false | Applies a group with parameter values. |
settings, script_phase | Build settings and Run Script phases. |
inherit! | :complete (default) links the parent target's packages; :none ignores them. |
platform, project | Override the defaults for this target. |
Settings and script phases of a concrete target stay on it; those of an abstract_target apply to every target nested in it. inherit! :search_paths is reserved and not supported yet.
Groups and includes
Put reusable declarations in a named group and share files with include. Because an included file may set platform, a shared file can also hold the deployment target of several projects.
# ../Shared/Base.podfile
platform :ios, '15.4'# ../Shared/Firebase.podfile
group :firebase do
spm 'Firebase', '13.0.1', products: %w[FirebaseCore FirebaseAnalytics]
end# Podfile
include '../Shared/Base.podfile'
include '../Shared/Firebase.podfile'
target 'Game' do
use :firebase
endGroup parameters
A group can declare true/false parameters with defaults. with blocks inside it apply while their parameter is true, and use overrides a value for one group:
# ../Shared/AppLovin.podfile
group :applovin_max, amazon: true do
spm 'AppLovinSDK', '13.6.4'
with :amazon do
binary 'AppLovinMediationAmazonAdMarketplaceAdapter', '5.6.4.0'
binary 'AmazonPublisherServicesSDK', '5.6.4'
end
endtarget 'Game' do
use :applovin_max # amazon: true
end
target 'Lite' do
use :applovin_max, amazon: false
endParameters only switch declarations on and off; they are never substituted into strings.
Checks
SwiftPods reports conflicts at both declarations: a package declared twice with different requirements, two packages with one identity, a build setting set twice for a target, an unknown group or target, a cycle of groups or includes. swiftpods check reads the Podfile without touching the project.
Frameworks embedded in an app
Xcode embeds a package's dynamic frameworks only into the target that links them. When an app embeds a framework target, as Unity's Unity-iPhone embeds UnityFramework, the framework links them but the app lacks them and fails at launch. So every target that embeds a framework target of the Podfile, declared or not, gets [SwiftPods] Finish, which copies those frameworks into the app without headers and modules, and signs them. Application targets also receive the framework runtime search path while preserving $(inherited): @executable_path/Frameworks on iOS and @executable_path/../Frameworks on macOS. This lets dyld find the embedded frameworks at launch. Explicit Podfile build settings remain overrides. See Unity.
DSL scope
Use spm and binary for dependencies, settings for build settings and script_phase for build-time scripts. pod, use_frameworks!, use_modular_headers!, inhibit_all_warnings!, workspace, install!, plugin, pre_install and post_install fail with an error that names the replacement. See Adopting SwiftPods for an existing project.