You can link a target to a package product similar to linking to a framework or library. Xcode automatically adds a package dependency to your project for you.
In the Project navigator, select the project, and in the project editor, select the target.
Click General, then under Frameworks, Libraries, and Embedded Content, click the Add button (+) below the table.
In the sheet that appears, choose Add Package Dependency from the Add Other pop-up menu.
In the next sheet, enter the Git repository that contains the package in the search field, or choose a Git repository from the list, then click Next.
If necessary, enter your credentials to access the Git repository in the dialog.
In the next sheet, specify the package version or versions that your project requires.
Select a version, range of versions, branch, or commit:
Version: Choose an option for specifying a version or versions from the Version pop-up menu:
Up to Next Major:
The latest version that is greater than or equal to the version that you enter in the text field, but less than the next major version. For example, if you enter 1.2.3, the latest version that is greater than or equal to 1.2.3 but less than 2.0.0.
Up to Next Minor:
The latest version that is greater than or equal to the version that you enter in the text field, but less than the next minor version. For example, if you enter 1.2.3, the latest version that is greater than or equal to 1.2.3 but less than 1.3.0.
Range:
A range of versions that are greater than or equal to the lower version, that you enter in the first text field, and less than the upper version, that you enter in the second text field.
Exact: The single version that you enter in the text field.
Branch: The version that corresponds to a branch that you enter in the text field.
Commit: The version that corresponds to the description that you enter in the text field.
Click Next.
Xcode downloads and resolves the package.
In the next sheet, choose a package product, then click Finish.
Note: You can only choose package products that build libraries. The Kind column specifies the type of library produced by the package; this can either be dynamic or static. If no explicit type is mentioned, the code links directly into the client.
The package target appears in the Frameworks, Libraries, and Embedded Content table in the General pane. The package dependency appears under Package Dependencies in the Project navigator (). Any issues that occur while adding the package dependency appear in the Report navigator (
).
The source control repository that contains the package also appears under Package Dependencies in the Source Control navigator.
To verify that the target links to the package product, view the Build messages in the Report navigator () when you build the target.
Alternatively, to create a package dependency, you can choose File > Swift Packages > Add Package Dependency, or select the project, then click the Add button (+) under the table on the Swift Packages pane. After you add a package dependency, follow the steps to link a target to a package product.