How to version swift packages

Viewed 4292

Using Xcode 12.4 and Swift 5.3 I have defined a package using the Package.swift manifest file. After including it in an app I want to update the package. To do that I have changed the link to the new release and updated the checksum; the relevant part of the file looks like this:

let package = Package(
    name: "MyPackage",
    // omitted platforms and products
    targets: [ .binaryTarget( name: "MyPackage",
                              url: "https://artifactory/mypackage-v1.1.zip",
                              checksum: "..." ) ] )

However, I get the error message artifact of binary target 'MyPackage' has changed checksum; this is a potential security risk so the new artifact won't be downloaded. This error can be ignored by deleting the entire DerivedData on folder, but that's obviously not updating the version number. Another solution is suggested in this answer, but again it doesn't affect versioning. The official documentation writes extensively about dependent package versions, but I cannot find how to specify the version of the CURRENT package.

How can I legitimately specify and update the version number so the new artifact gets identified as a distinct new version and downloaded properly?

1 Answers

When you want to distribute (privately or publicly) a closed source package using an xcframework file you typically need to create a git repository that only contains the Package.swift file in which you declare the binaryTarget. (or the binaryTargets) Whichever have access to this repository should also have access to the url that you declare in the binaryTarget in order to install your package.

As @Larme and @matt correctly mentioned in the comments, to specify which commit correspond to each version, you have to use tags in the git repository exactly like you do in a cocoapod repository, only you will do this in a repository that contains only the Package.swift file. See "Tag Your Latest Commit" section in the Publishing a Swift Package with Xcode documentation for more details.

You can use as an example the PSPDFKit, which is a known and well maintained closed source package that can be installed using this github repository.

Related