> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/artifact-registry/new-to-artifact-registry/quickstart/swift-quickstart.md).

# Swift

{% @harness-package-selector/package-selector platforms="%5B%7B%22label%22%3A%22Docker%22%2C%22slug%22%3A%22docker%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fdocker-quickstart%22%7D%2C%7B%22label%22%3A%22Helm%22%2C%22slug%22%3A%22helm%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fhelm-quickstart%22%7D%2C%7B%22label%22%3A%22Helm%20HTTP%22%2C%22slug%22%3A%22helm-http%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fhelm-http-quickstart%22%7D%2C%7B%22label%22%3A%22Generic%22%2C%22slug%22%3A%22generic%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fgeneric-quickstart%22%7D%2C%7B%22label%22%3A%22Raw%20File%22%2C%22slug%22%3A%22raw-file%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fraw-file-quickstart%22%7D%2C%7B%22label%22%3A%22Maven%22%2C%22slug%22%3A%22maven%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fmaven-quickstart%22%7D%2C%7B%22label%22%3A%22Python%22%2C%22slug%22%3A%22python%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fpython-quickstart%22%7D%2C%7B%22label%22%3A%22NPM%22%2C%22slug%22%3A%22npm%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fnpm-quickstart%22%7D%2C%7B%22label%22%3A%22Nuget%22%2C%22slug%22%3A%22nuget%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fnuget-quickstart%22%7D%2C%7B%22label%22%3A%22RPM%22%2C%22slug%22%3A%22rpm%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Frpm-quickstart%22%7D%2C%7B%22label%22%3A%22Debian%22%2C%22slug%22%3A%22debian%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fdebian-quickstart%22%7D%2C%7B%22label%22%3A%22Alpine%22%2C%22slug%22%3A%22alpine%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Falpine-quickstart%22%7D%2C%7B%22label%22%3A%22Wolfi%22%2C%22slug%22%3A%22wolfi%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fwolfi-quickstart%22%7D%2C%7B%22label%22%3A%22Cargo%22%2C%22slug%22%3A%22cargo%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fcargo-quickstart%22%7D%2C%7B%22label%22%3A%22Conan%22%2C%22slug%22%3A%22conan%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fconan-quickstart%22%7D%2C%7B%22label%22%3A%22Go%22%2C%22slug%22%3A%22go%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fgo-quickstart%22%7D%2C%7B%22label%22%3A%22Hugging%20Face%22%2C%22slug%22%3A%22hugging-face%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fhugging-face-quickstart%22%7D%2C%7B%22label%22%3A%22Conda%22%2C%22slug%22%3A%22conda%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fconda-quickstart%22%7D%2C%7B%22label%22%3A%22Dart%22%2C%22slug%22%3A%22dart%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fdart-quickstart%22%7D%2C%7B%22label%22%3A%22PHP%20Composer%22%2C%22slug%22%3A%22php-composer%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fphp-composer-quickstart%22%7D%2C%7B%22label%22%3A%22Swift%22%2C%22slug%22%3A%22swift%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fswift-quickstart%22%7D%2C%7B%22label%22%3A%22Puppet%22%2C%22slug%22%3A%22puppet%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fpuppet-quickstart%22%7D%2C%7B%22label%22%3A%22Terraform%22%2C%22slug%22%3A%22terraform%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fterraform-quickstart%22%7D%2C%7B%22label%22%3A%22R%20(CRAN)%22%2C%22slug%22%3A%22r-cran%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fr-cran-quickstart%22%7D%2C%7B%22label%22%3A%22RubyGems%22%2C%22slug%22%3A%22rubygems%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Frubygems-quickstart%22%7D%5D" selectedPlatform="swift" %}

Use a **Swift** registry to publish and consume Swift packages with **Swift Package Manager (SwiftPM)**. Harness exposes a registry URL compatible with `swift package-registry` commands for authentication, publishing, and dependency resolution.

{% hint style="info" %}
**FEATURE FLAG**

This feature is behind the feature flag `HAR_SWIFT_PACKAGE`. Contact [Harness Support](mailto:support@harness.io) to enable it.
{% endhint %}

### Prerequisites <a href="#prerequisites" id="prerequisites"></a>

* **Swift 5.9 or later** with Swift Package Registry support (`swift package-registry --help`).
* Access to a Harness account with appropriate permissions to create registries and connectors.

***

### Create a Swift Artifact Registry <a href="#create-a-swift-artifact-registry" id="create-a-swift-artifact-registry"></a>

{% tabs %}
{% tab title="Interactive Guide" %}
{% embed url="<https://app.tango.us/app/embed/81c74d78-4354-4b0b-8a40-a3579c8f7536?skipCover=true&defaultListView=false&skipBranding=false&makeViewOnly=true&hideAuthorAndDetails=true>" %}
Create a Swift registry in Harness
{% endembed %}
{% endtab %}

{% tab title="Step-by-Step" %}

1. Navigate to the Artifact Registry module in your Harness project.
2. Click on **New Artifact Registry**.
3. In the Registry Type dropdown, select **Swift Registry** (or **Swift Package Registry**).
4. Provide a **Registry Name**.

{% hint style="info" %}
**REGISTRY NAME CRITERIA**

Your registry name must start with a letter and can include `lowercase alphanumerics`, `_`, `.` and `-`.
{% endhint %}

5. Optionally, add a Description and Labels for better organization.
6. Choose visibility between **Public** and **Private**.
7. Click **Create Registry** to finalize.
   {% endtab %}
   {% endtabs %}

{% hint style="info" %}
**PRIVATE REGISTRY**

This registry will serve as your private Swift registry within Harness.
{% endhint %}

***

### Configure an Upstream Proxy (Optional) <a href="#configure-an-upstream-proxy-optional" id="configure-an-upstream-proxy-optional"></a>

An upstream proxy allows your registry to fetch Swift packages from external sources when they are not available locally.

{% tabs %}
{% tab title="Interactive Guide" %}

#### Create an upstream proxy

{% embed url="<https://app.tango.us/app/embed/44c521ee-2136-49e8-901d-89dfd30e6e22?skipCover=true&defaultListView=false&skipBranding=false&makeViewOnly=true&hideAuthorAndDetails=true>" %}
Create a Swift upstream proxy
{% endembed %}

#### Configure the upstream proxy in your registry

{% embed url="<https://app.tango.us/app/embed/3dde6766-afe5-4386-8747-511441b22661?skipCover=true&defaultListView=false&skipBranding=false&makeViewOnly=true&hideAuthorAndDetails=true>" %}
Attach the upstream proxy to your Swift registry
{% endembed %}
{% endtab %}

{% tab title="Step-by-Step" %}

#### Create an upstream proxy

1. In the Artifact Registry module, select **Upstream Proxy**.
2. Choose **Swift** as the proxy type.
3. Enter an **Upstream Proxy Name**. Optionally add a **Description** and **Labels**.
4. Under **Source**, enter the **Remote Registry URL** for the upstream Swift Package Registry.
5. Under **Authentication**, select **Anonymous (No credentials required)** or **Username and Password**, depending on whether the upstream requires credentials.
6. Click **Create Proxy** to establish the connection.

#### Configure the upstream proxy in your registry

1. In the Artifact Registry module, select an existing **Swift Artifact Registry**.
2. Select the **Configuration** tab.
3. Under **Advanced (Optional)**, select **Configure Upstream**.
4. Select from the list of compatible proxies to add them to your registry.
5. Click **Save** to save the configuration.
   {% endtab %}
   {% endtabs %}

***

### Swift Client Setup <a href="#swift-client-setup" id="swift-client-setup"></a>

Follow these instructions to configure SwiftPM, publish packages to Harness, and add them as dependencies in your projects.

#### Configure authentication <a href="#configure-authentication" id="configure-authentication"></a>

**1. Generate Identity Token**

An identity token serves as the credential for Swift Package Registry operations.

Generate an identity token from **Setup Client** on your Swift registry, or from your Harness account settings. Use it as `<TOKEN>` in the commands below.

**2. Point SwiftPM at the Harness registry**

Set the Swift Package Registry URL for your Harness registry:

```bash
swift package-registry set https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/swift
```

Replace `<ACCOUNT_ID>` and `<REGISTRY_NAME>` with your account identifier and registry name. Use the URL shown in **Setup Client** if it differs.

**3. Authenticate with your token**

```bash
swift package-registry login https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/swift --token <TOKEN>
```

Use the same registry URL as in step 2 and the `<TOKEN>` from step 1. Copy the exact URL from **Setup Client** when it differs from the example host or path.

#### Publish a package <a href="#publish-a-package" id="publish-a-package"></a>

Publish a package version to your Harness Swift registry.

{% hint style="info" %}
**SWIFT PACKAGE IDENTITY MUST BE `SCOPE.NAME`**

Every value used for `<ARTIFACT_NAME>` (the Swift package identity) must be in `scope.name` form — for example `mona.LinkedList` or `harness.SwiftTestPkg`. Both `scope` and `name` start with a letter and may contain letters, digits, hyphens, and underscores. Harness rejects identifiers that are missing the dot, contain more than one dot, or use other characters.
{% endhint %}

**Basic publish:**

```bash
swift package-registry publish <ARTIFACT_NAME> <VERSION>
```

**With metadata (recommended):**

```bash
swift package-registry publish <ARTIFACT_NAME> <VERSION> --metadata-path metadata.json
```

**With metadata and signatures (optional):**

```bash
swift package-registry publish <ARTIFACT_NAME> <VERSION> \
  --metadata-path metadata.json \
  --private-key-path private-key.der \
  --cert-chain-paths cert-chain.der
```

Replace `<ARTIFACT_NAME>` and `<VERSION>` with your package identity and semantic version. Prepare `metadata.json` and signing paths as required by your signing policy.

#### Install a package <a href="#install-a-package" id="install-a-package"></a>

**1. Add a package dependency in `Package.swift`**

Add a package-level dependency:

```swift
dependencies: [
    .package(id: "<ARTIFACT_NAME>", from: "<VERSION>"),
],
```

**2. Add a target dependency**

Reference the product from your library or executable target:

```swift
targets: [
    .target(
        name: "YourTarget",
        dependencies: [
            .product(name: "<PRODUCT_NAME>", package: "<ARTIFACT_NAME>")
        ]
    )
]
```

Replace `<PRODUCT_NAME>` with the product name exposed by the package.

**3. Resolve dependencies**

Fetch and resolve packages:

```bash
swift package resolve
```

**4. (Optional) Fetch packages from the registry instead of Git**

If your `Package.swift` still references dependencies by Git URL, you can resolve using the registry:

```bash
swift package --replace-scm-with-registry resolve
```

To complete the in-product flow, click **Done** in **Setup Client** if you are following the in-product wizard.
