Swift Packages
Artifacts implements the full SE-0292 Swift Package Registry protocol. Swift Package Manager resolves, downloads, and installs packages from your Artifacts registry natively -- no wrapper scripts or custom tooling required.
Replace ORGSLUG and REPOSLUG with your actual organization and repository slugs in every example below.
Registry Setup
Tell Swift Package Manager where your registry lives:
swift package-registry set https://artifacts.premex.se/api/swift/ORGSLUG/REPOSLUG/
This writes the registry URL to your Swift PM configuration. The setting persists across builds.
Tip: You can scope the registry to a specific project by running the command inside the project directory, or set it globally with
--global.
Authentication
Log in to the registry so Swift PM can authenticate when resolving packages:
swift package-registry login https://artifacts.premex.se/api/swift/ORGSLUG/REPOSLUG/ --token art_your_token
Swift PM stores the credential securely in your system keychain. You only need to run this once per machine (or once per CI environment).
For CI environments where the keychain is not available, you can set the token via a netrc file:
# ~/.netrc
machine artifacts.premex.se
login token
password art_your_token
Important: Ensure
~/.netrchas restricted permissions (chmod 600 ~/.netrc) and is never committed to source control.
Consuming Packages
Add a dependency in Package.swift
Swift Package Registry uses a scope.name identifier format. Add the dependency to your Package.swift:
dependencies: [
.package(id: "scope.package-name", from: "1.0.0"),
]
For example, if your package scope is myorg and the package name is hello-lib:
dependencies: [
.package(id: "myorg.hello-lib", from: "1.0.0"),
]
Use the package in a target
targets: [
.target(
name: "MyApp",
dependencies: [
.product(name: "HelloLib", package: "myorg.hello-lib"),
]
),
]
Resolve and build
swift package resolve
swift build
Swift PM will fetch the package metadata and source archive from your Artifacts registry.
Package Naming
Swift packages in Artifacts use a scope.name convention:
| Component | Example | Description |
|---|---|---|
| Scope | myorg |
Organization or namespace |
| Name | hello-lib |
Package name (lowercase, hyphens allowed) |
| Identifier | myorg.hello-lib |
Combined ID used in Package.swift |
The scope and name together form the unique package identifier within a repository.
Publishing
Using the Swift Package Registry protocol
If your version of Swift PM supports registry publishing:
swift package-registry publish scope.package-name 1.0.0
Using curl
Create a source archive (zip of the Swift package) and upload it directly:
# Create the source archive
zip -r source-archive.zip Package.swift Sources/ Tests/ -x "*.DS_Store" ".build/*"
# Upload
curl -X PUT \
"https://artifacts.premex.se/api/swift/ORGSLUG/REPOSLUG/SCOPE/PACKAGE_NAME/VERSION" \
-H "Authorization: Bearer art_your_token" \
-H "Content-Type: application/zip" \
--data-binary @source-archive.zip
For example:
curl -X PUT \
"https://artifacts.premex.se/api/swift/myorg/myrepo/myorg/hello-lib/1.0.0" \
-H "Authorization: Bearer $ARTIFACTS_TOKEN" \
-H "Content-Type: application/zip" \
--data-binary @source-archive.zip
Publishing requires a token with write scope. A successful upload returns HTTP 201.
Xcode Integration
Xcode uses Swift PM under the hood for package resolution. To use Artifacts packages in an Xcode project:
Set the registry on your machine using the
swift package-registry setcommand (see Registry Setup above). Xcode respects the same Swift PM configuration.Log in using
swift package-registry loginso Xcode can authenticate.Add the dependency in Xcode:
- Open your project and go to File > Add Package Dependencies...
- In the search field, enter the package identifier (e.g.,
myorg.hello-lib) - Xcode will query the configured registry and show available versions
- Select the version range and add it to your target
Build the project. Xcode downloads the source archive from Artifacts and builds it as part of your project.
Tip: If Xcode does not find the package, verify the registry is configured by running
swift package-registry getin a terminal. Also check that you are logged in (swift package-registry login).
CI/CD Example
A GitHub Actions workflow for publishing a Swift package:
name: Publish Swift Package
on:
push:
tags:
- 'v*'
jobs:
publish:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Create source archive
run: zip -r source-archive.zip Package.swift Sources/ Tests/ -x "*.DS_Store" ".build/*"
- name: Publish to Artifacts
run: |
curl -f -X PUT \
"https://artifacts.premex.se/api/swift/myorg/myrepo/myscope/my-package/${GITHUB_REF_NAME#v}" \
-H "Authorization: Bearer ${{ secrets.ARTIFACTS_TOKEN }}" \
-H "Content-Type: application/zip" \
--data-binary @source-archive.zip
The ${GITHUB_REF_NAME#v} expression strips the v prefix from the tag (e.g., v1.0.0 becomes 1.0.0).
Versions API
Query published versions for any package via a simple HTTP endpoint -- useful for CI/CD scripts, update checkers, or install scripts.
# JSON — all versions with metadata
curl -s https://artifacts.premex.se/api/v/ORGSLUG/REPOSLUG/PACKAGE/versions
# Plain text — latest version only
curl -s https://artifacts.premex.se/api/v/ORGSLUG/REPOSLUG/PACKAGE/versions?format=txt\&limit=1
This endpoint works for all package types. Public repos require no authentication.
Troubleshooting
"No registry configured"
Run swift package-registry set to configure the registry URL. If you set it inside a project directory, it only applies to that project. Use --global for a machine-wide setting.
401 Unauthorized
- Verify you have logged in with
swift package-registry login. - Check that your token has not expired in the web UI under Settings > API Tokens.
- On CI, ensure the netrc file or token is correctly configured.
Package not found
- Double-check the package identifier format:
scope.name(e.g.,myorg.hello-lib), not a URL. - Verify the package has been published to the correct repository. Check the web UI for the list of packages.
- Ensure the org slug and repo slug in the registry URL are correct.
Source archive download fails
- Make sure the source archive is a valid zip file containing
Package.swiftat the root level. - Verify the version number in your
Package.swiftdependency matches a published version.
Xcode cannot resolve the package
- Reset the Swift PM cache: File > Packages > Reset Package Caches in Xcode.
- Verify the registry is set and you are logged in by running the following in a terminal:
swift package-registry get