Adding and Removing Swift Package dependencies in Xcode

⋅ 2 min read ⋅ Xcode Swift Package

Table of Contents

Apple introduced Swift Package Manager (SPM) in 2017 as a way to manage dependencies in Swift. Then two years later (Xcode 11), SPM has fully integrated into Xcode. We can easily manage Swift Package dependencies since then.

In this article, I will show you how easy it is to manage Swift Package dependencies in Xcode.

  1. Adding a Package dependency to your app.
  2. Updating a Package dependency.
  3. Removing a Package dependency.

Adding a Package dependency

To add a package dependency to your Xcode project.

  1. Select File > Add Packages...
  2. Enter a repository URL of a package you want to add in the search field on the top right. In this example, I try to add Swift Algorithms package, and this is the URL I use
Enter a package repository URL.
Enter a package repository URL.
  1. Select a version you want to add to the Dependency Rule.
Dependency Rule.
Dependency Rule.
  1. Then, click the "Add Package" button to add.

You can also add a package dependency from your target's General pane.

  1. Click on the target that you want to add a package.
  2. Select the General pane.
  3. Scroll down to the "Frameworks, Libraries, and Embedded Content" section.
  4. Click the + button, select "Add Other...", and choose "Add Package Dependency...".
Add Package Dependency.
Add Package Dependency.

Updating a Package dependency

To update an individual package.

  1. Find a package you want to update in the Project Navigator. All packages sit at the bottom of the panel under the "Package Dependencies" section, so you need to scroll down a bit.
  2. Right-click on the package and choose "Update Package" action.
Update individual package.
Update individual package.

To update all packages.

  1. Right-click on the Package Dependencies section header.
  2. Choose "Update to Latest Package Versions".

Or Select File > Packages > Update to Latest Package Versions.

Update all packages.
Update all packages.

Removing a Package dependency

If you no longer need any package, you can remove it using these steps.

  1. Click on the project root file.
  2. Select the "Package Dependencies" pane.
  3. Select the Swift package you want to delete from the list.
You can see all packages in Package Dependencies pane.
You can see all packages in Package Dependencies pane.
  1. Click the minus (-) button to remove the selected package.
Click the minus button to remove the package.
Click the minus button to remove the package.

Read more article about Xcode, Swift Package, or see all available topic

Enjoy the read?

If you enjoy this article, you can subscribe to the weekly newsletter.
Every Friday, you'll get a quick recap of all articles and tips posted on this site. No strings attached. Unsubscribe anytime.

Feel free to follow me on Twitter and ask your questions related to this post. Thanks for reading and see you next time.

If you enjoy my writing, please check out my Patreon and become my supporter. Sharing the article is also greatly appreciated.

Become a patron Buy me a coffee Tweet Share
SwiftUI Checkbox

Learn how to create a checkbox in iOS with SwiftUI.

Easy way to Format Date in SwiftUI Text

Since iOS 14, SwiftUI Text has had many initializers dedicated to presenting dates. Let's explore all of them.

← Home