I have an Xcode project with a package dependency and want to add that package dependency locally for editing within my app project, but Xcode reports an error when trying to add the package locally.
Apple docs reference: Editing a package dependency as a local package
What I have tried:
-
I cloned that package dependency from github to a folder on my Mac.
-
I selected File/Add Package Dependencies… and then "Add Local…", selected the local folder with the cloned package to add it as a local package for editing to my Xcode project.
-
I expected Xcode to override my (remote) package dependency with the local package. But Xcode reports an error ‘can not resolve package dependency graph…’.
-
If I select "Add Anyways" the local package is not added to the project.
2
Answers
With Xcode 15.2 I successfully added the cloned package as a local package for editing, by dragging and dropping the local package into my Xcode project right below the project name, instead of using File/Add Package Dependencies...
Xcode does override the (remote) package dependency. It shows this by removing the package dependency from the Project Navigator.
If you remove the local package again, the remote package dependency shows up again in the Project Navigator.
Here is how you can do it:
1. Using Xcode’s built-in features (for Xcode 11 and later)
Xcode has built-in support for Swift Package Manager, and starting from Xcode 11, it allows you to seamlessly work with package dependencies:
When you choose to edit a package in place, Xcode creates a local copy of the package that you can edit. Any changes you make will be reflected in your project immediately. This is useful for debugging or making quick modifications to a package.
2. Modifying package dependency to point to a cocal copy
If you need more control or wish to work with a local copy of a package (for instance, for extensive modifications or because you’re contributing to the package), you can modify your
Package.swift
file to point to a local path:Package.swift
file. This file contains the dependencies for your project.dependencies
array./path/to/local/package
, you would modify the dependency like this:3. Keep in mind and don’t forget about:
Package.swift
file or through Xcode’s package management interface.Let me know if any questions.