← Articles

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

Updated in

  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.

For a more complete library, the Swift Package Index 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.

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

Update a single package

Find your 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

Update all packages

Control-click (right-click) Package Dependencies in the Project Navigator.

Select Update to Latest Package Versions.

Xcode‘s context menu options for all package dependencies

Remove packages

Remove from a 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.

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

Remove from project (all targets)

Select your project in the Project Editor.

In the Package Dependencies tab, select the package you want to remove.

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


— Alex