skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.


  2. 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:

    1. Open your Xcode project.
    2. Navigate to the Swift Packages tab in your project settings.
    3. Find the package you wish to edit. You can see the list of added packages in this section.
    4. Right-click on the package and choose "Edit Package in Place". This option allows you to modify the package’s source code directly within your project’s workspace.

    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:

    1. Locate your Package.swift file. This file contains the dependencies for your project.
    2. Identify the package dependency you wish to edit. It will be listed under the dependencies array.
    3. Change the package dependency to point to a local path. For example, if you have a local copy of the package at /path/to/local/package, you would modify the dependency like this:
    .package(path: "/path/to/local/package")
    

    3. Keep in mind and don’t forget about:

    • Version Control: If you’re editing a package locally for the purpose of contributing back to the original repository, make sure to branch and follow the contributing guidelines of the package.
    • Reverting Back: Once you’re done with local edits and you want to switch back to using the remote package, you’ll need to revert the changes made in your Package.swift file or through Xcode’s package management interface.
    • Dependencies: If the local package has dependencies, ensure they are also resolved correctly. SPM should handle this, but it’s something to be aware of if you encounter build issues.

    Let me know if any questions.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search