Local Package with Relative-Path within Xcode

Related to How to add local Swift Package as dependency? but it didn't seem to be resolved

My Understanding:

Within the Package.swift manifest you can add a dependency with a relative URL .package(url: "../../Foo/Baz", from: "1.0.0") However attempting to do something similar in Xcode just gives a generic response (tried various relative URLs and nothing has worked):
11%20PM

There is a way to access local package with the absolute URL: file:///Users/UserName/Documents/Foo/Baz. You can also "Override" a package dependency by directly adding it to your workspace.

My Question:

Is there any way to make relative paths work in Xcode's package management, or a definition of where the relative-url resolves from?

If not, is there a plan on adding support?

My Use Case: Using the package from a project within the same repo

With a folder setup like:

PackageFolder 
    ->Package.Swift
    ->Sources
    ->TestProject
        ->TestProject.xcodeproj

A File:// reference isn't generic, so won't work for a shared/public project.

A workspace could be used, but the only way to add the Package is to add the PackageFolder, which also will include the TestProject.xcodeproj as a generic file.

Attempting to then add TestProject.xcodeproj to the workspace currently causes a crash, and I doubt will be supported regardless of whether that's fixed.

My workaround is generating the xcodeproj from the SPM module, but that uses the generated Framework target rather than the actual SPM Package and uses the local files not the git-tag/branch/commit. So e.g. you couldn't have a project that pulls "Version 1.0" and a project that pulls "Version 2.0".

2 Likes

Creating a workspace and adding both the project and the Swift package worked for me.

hm...seems to work with a simple project. Xcode froze multiple times when I tried it with a "real" project. That might just be a bug then. In that case that's another workaround, assuming it works for the project :slight_smile:

It looks like maybe you resolved this? What was you final solution?

Much has happened in the original thread since this one was spun off. You may find your answer there.