4

I recently forked a Swift Package library from GitHub in order to implement a functionality that I've been missing. However, when I try to add my version of the package in a Xcode project (by adding the url of my fork), Xcode can't find any results.

Xcode shows that it found 0 results for my fork

Is this an intended limitation of Swift Package Manager or am I missing something?

ajpallares
  • 777
  • 4
  • 16

3 Answers3

10

I finally worked around this limitation by manually editing both the project.pbxproj and Packages.resolved files, so that they point to the specific commit in the fork of the repository.

To do this, close Xcode and then open the two files with a plain text editor.

In the project.pbxproj file, change the url of the repo and the parameters needed to correctly specify the version rule. In my case, I wrote the hash of the commit I needed:

/* Begin XCRemoteSwiftPackageReference section */
    7902F77227C64GF9001583F1 /* XCRemoteSwiftPackageReference "Cuckoo" */ = {
        isa = XCRemoteSwiftPackageReference;
        repositoryURL = "https://github.com/ajpallares/Cuckoo";
        requirement = {
            kind = revision;
            revision = a9d239ff1bb93fe0204f8285d513f3139b51fbbb;
        };
    };

Do the same for the Packages.resolved file:

{
  "package": "Cuckoo",
  "repositoryURL": "https://github.com/ajpallares/Cuckoo",
  "state": {
    "branch": null,
    "revision": "a9d239ff1bb93fe0204f8285d513f3139b51fbbb",
    "version": "null"
}

Obviously, this is not the ideal solution but at least it works ¯\(ツ)

In fact, this seems to be an intended limitation of Swift Package Manager. See:

ajpallares
  • 777
  • 4
  • 16
  • Did you tagged the commit you want to use with the highest Version number? I don't have the issues you described. – LoVo Feb 25 '22 at 15:51
  • I did not tag the commit at all. But I believe tagging it should not be necessary – ajpallares Mar 04 '22 at 11:08
1

Try to use http instead of https: http instead of https

EDIT:

After you tried with http and still have the problem you probably need to create a personal access token:

  1. Go to GitHub and log in.
  2. In the upper right corner you will see your avatar with a button to open a menu. Click and choose Settings.
  3. Choose Developer Settings from the list of settings.
  4. Choose Personal Access Tokens from the list of developer settings.
  5. Click the Generate a personal access token link.
  6. Enter Xcode in the Note text field to let you know the token is for Xcode.
  7. Select the scopes for the access token.
  8. Click the Generate token button.
  9. Copy the token so you can paste it in Xcode.

Now to use the token in Xcode:

  1. Choose Xcode > Preferences.
  2. Click the Accounts button at the the top of the preferences window.
  3. Click the Add button.
  4. Choose GitHub from the list of accounts.
  5. Click the Continue button.
  6. Enter your GitHub username and personal access token in the text fields.
  7. Click the Sign In button.
LoVo
  • 1,856
  • 19
  • 21
  • 2
    Nope. Still the same issue with http... – ajpallares Feb 21 '22 at 09:21
  • Thanks for the (edited) answer. It looks like it's a limitation of Swift Package Manager (perhaps intended). See: https://forums.swift.org/t/dependency-mirroring-and-forking/13902 https://forums.swift.org/t/replace-dependency-in-graph-with-a-fork/39718 – ajpallares Feb 23 '22 at 11:41
  • Ok, but i am able to add the package from the url in your screenshot. `http://github.com/ajpallares/Cuckoo.git` – LoVo Feb 23 '22 at 13:11
  • Really? Then maybe it's some caching or bug in Xcode I'll keep checking this. Thank you! – ajpallares Feb 25 '22 at 09:27
1

In Xcode 14.0.1 started to work by defining commit hash like this: enter image description here

Ramis
  • 13,985
  • 7
  • 81
  • 100