---
title: Adding package dependencies to your app
framework: xcode
role: article
role_heading: Article
path: xcode/adding-package-dependencies-to-your-app
---

# Adding package dependencies to your app

Integrate package dependencies to share code between projects, or leverage code from other developers.

## Overview

Overview Xcode comes with built-in support for source control accounts and makes it easy to leverage available Swift packages. Use Xcode to manage the versions of package dependencies and make sure your project has the most up-to-date code changes. note: A package author can publish their Swift package to either public or private repositories. Xcode supports both private and publicly available packages. Add a package dependency To add a package dependency to your Xcode project, select File > Add Package Dependency and enter its source control repository URL. You can also navigate to your target’s General pane, and in the “Frameworks, Libraries, and Embedded Content” section, click the + button, select Add Other, and choose Add Package Dependency.

Instead of adding a source control repository URL, you can search for a package on GitHub or GitHub Enterprise. Add your GitHub or GitHub Enterprise account in Xcode’s settings, and a list of package repositories appears as you type. The following screenshot shows a list of repositories for the search term ExamplePackage for a user who added their Git provider in Xcode’s settings.

If you’ve added a source control account in Xcode’s settings and you haven’t yet entered a search term, the list contains package repositories from: Your Git Repositories Your team’s Git repositories Your starred repositories on GitHub, GitHub Enterprise, GitLab, or your self-managed GitLab instance important: Only add package dependencies by trustworthy authors. In addition, adding a binary dependency comes with drawbacks over adding a source-based dependency. See Identifying binary dependencies to learn more. Decide on package requirements When you enter the package dependency’s URL or pick a Swift package from the list of packages, choose one of three package requirements. Package requirements determine the allowed versions of the package dependency in your project, and Xcode updates your package dependency based on the requirement that you choose. After you choose a package requirement, Xcode resolves and fetches the package dependency. Select the package’s products that you need, and add them to targets in your project. In Xcode’s Project navigator, the Swift Package Dependencies section shows the newly added package dependency. Click the disclosure triangle to view the contents of the package as it exists locally on your Mac. tip: Although Xcode updates your package dependencies and resolves package versions automatically, you can trigger both actions from the File > Packages menu. Use features and assets provided by a Swift package To use a Swift package’s functionality in your app, import a package’s product as a Swift module. The following code snippet shows a view controller that imports a Swift package’s MyLibrary module and uses the package’s functionality: import UIKit

// Import the module that corresponds with the Swift package’s library product MyLibrary. import MyLibrary

class ViewController: UIViewController {

@IBOutlet var aLabel: UILabel!     @IBOutlet var aButton: UIButton!     @IBOutlet var anImageView: UIImageView!     @IBOutlet var aCustomView: CustomView!

override func viewDidLoad() {         super.viewDidLoad()

// Use a string that the package exposes as a property in the MyLibrary file.         self.aLabel.text = MyLibrary.titleText

// Load an image that the MyLibrary package makes available through a class method.         if let imagePath = MyClass.exampleImagePath() {             self.anImageView.image = UIImage(contentsOfFile: imagePath)         }

// Use the Swift package’s CustomView class.         self.aCustomView = CustomView()     }

// Show an alert by calling the package’s API.     @IBAction func showAlert(_ sender: Any) {         MyClass.showAlertUsing(viewController: self)     } } Edit a package dependency You can’t edit the content of your package dependencies directly. If you want to make changes to a package dependency, you need to add it as a local package to your project. See Editing a package dependency as a local package to learn how you can override a package dependency with a local package and make edits. Coordinate package versions across your team When collaborating on a project, make sure everyone uses the same version of a package dependency. When you add a package dependency to a project, Xcode creates the Package.resolved file. It lists the specific Git commits to which each package dependency resolves and the checksum of each binary dependency. Commit this file in Git to ensure that everyone is using the same version of a package dependency. tip: You can find the Package.resolved file inside your .xcodeproj directory at [appName].xcodeproj/project.workspace/xcshareddata/swiftpm/Package.resolved. Delete a package dependency To remove a package dependency from your Xcode project: Select your project in the Project Editor and navigate to the Packages Dependencies pane. Select the package from the list of package dependencies. Click the - button from the bottom of the list and click Remove to confirm.

## See Also

### Project configuration

- [Managing your app’s information property list values](bundleresources/managing-your-app-s-information-property-list.md)
- [Creating a Mac version of your iPad app](uikit/creating-a-mac-version-of-your-ipad-app.md)
- [Setting up a watchOS project](watchos-apps/setting-up-a-watchos-project.md)
- [Embedding a command-line tool in a sandboxed app](xcode/embedding-a-helper-tool-in-a-sandboxed-app.md)
