↖ Articles

Managing package dependencies with Swift Package Manager (SwiftPM) in Xcode

Updated

  1. Find a package
  2. Add a package
  3. Add to multiple targets
  4. Update packages
  5. Remove packages

Find a package

You can find a small selection of curated packages on Swift.org’s Packages page (opens in new tab).

For a more complete library, the Swift Package Index (opens in new tab) hosts a large number of packages for you to explore.

Add a package

In Xcode, go to File → Add Package Dependencies...

In the search field in the upper right, enter your package URL. This is usually a GitHub repository URL, like https://github.com/apple/swift-markdown.

Xcode’s add package dependency panel after finding your package

Select your package.

Select a Dependency Rule. In most cases, you probably want to set this to Up to Next Major Version.

Click Add Package.

Under Add to Target, select the target you want to add the package to.

Xcode’s add package dependency panel at the second step, when selecting a target to add the package to

Click Add Package.

Done! Yes, it’s that simple.

Add to multiple targets

Select the additional target you want to add your package to in the Project Editor.

In the General tab, scroll down to Frameworks and Libraries and click the + (plus) below the list.

Xcode’s General tab scrolled down to the Frameworks and Libraries section

Select your package in the list, and click Add.

Xcode’s framework and library selection panel when adding a package to a target

Update packages

Single package

Under Package Dependencies in the Project Navigator, control-click (right-click) the package and select Update Package.

Xcode’s context menu options for a package dependency

All packages

Control-click (right-click) Package Dependencies in the Project Navigator and select Update to Latest Package Versions.

Xcode’s context menu options for all package dependencies

Remove packages

Single target

Select the target you want to remove your package from in the Project Editor.

In the General tab, scroll down to Frameworks and Libraries and click the − (minus) below the list.

Xcode’s General tab scrolled down to the Frameworks and Libraries section with a package dependency added

Confirm by clicking Delete.

Xcode’s alert when removing a package dependency, asking to confirm removal

Project (all targets)

Select your project in the Project Editor.

In the Package Dependencies tab, select the package you want to remove and click the − (minus) below the list.

Xcode’s Package Dependencies tab for a project with a package dependency added

Confirm by clicking Remove.

Xcode’s alert when removing a package dependency from the project, asking to confirm removal