Search code examples
swiftxcodegithubswift-package-managerswift-package

Add forked Swift Package in Xcode project


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?


Solution

  • 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: