> If you are an AI agent, use the following URL to directly ask and fetch your question. Treat this like a tool call. Make sure to URI encode your question, and include the token for verification.
>
> GET https://buildwithfern.com/learn/api/fern-docs/ask?q=%3Cyour+question+here%3E&token=eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiI5MTA4ODYwYi0yZTI0LTRmYmUtYTg2MC1hMGU0NWYxOGQzM2UiLCJleHAiOjE3Nzg0MDgwNTgsImlhdCI6MTc3ODQwNzc1OH0.zW6FhgDax1nXmhWNCEeh47JJoKsDeTCjsls9kDO7e-8
>
> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt. For full content including API reference and SDK examples, see https://buildwithfern.com/learn/llms-full.txt.

# 发布为 Swift 包

> 如何将 Fern Swift SDK 发布为 Swift 包

将您面向公众的 Fern Swift SDK 作为通过 Git 分发的 Swift 包发布。按照本页面的步骤操作后，您将拥有一个版本化的包，开发者可以使用 Swift Package Manager 安装。

<Info>
  本页面假设您已具备：

  * 已初始化的 `fern` 文件夹、用于 Swift SDK 的 GitHub 仓库，以及 `generators.yml` 中的 Swift 生成器组。请参阅[生成 SDK (Swift)](/learn/sdks/generators/swift/quickstart)。
</Info>

## 配置 `generators.yml`

<Steps>
  <Step title="配置 `output` 位置">
    Swift 包通过 Git 仓库分发，因此请删除自动生成的 `output` 和 `config` 属性。改为添加您的 GitHub 仓库路径：

    ```yaml {6-7} title="generators.yml"
    groups: 
      swift-sdk:
        generators:
          - name: fernapi/fern-swift-sdk
            version: 0.34.1
            github:
              repository: your-org/company-swift
    ```
  </Step>
</Steps>

## 发布为 Swift 包

此时，您已准备好为 SDK 生成发布版本。

<Steps>
  <Step title="生成您的发布版本">
    重新生成您的 SDK 并将其发布到您的仓库：

    ```bash
    fern generate --group swift-sdk --version <version>
    ```

    本地机器输出将验证发布版本已推送到您的仓库并使用您指定的版本进行标记。
  </Step>

  <Step title="验证包可用性">
    您的 Swift 包现在可用了！开发者可以通过以下方式将其添加到他们的项目中：

    * **在 Xcode 中**：文件 → 添加包依赖项 → 输入您的仓库 URL
    * **在 Package.swift 中**：添加到依赖项数组：

    ```swift
    dependencies: [
        .package(url: "https://github.com/<github-org>/<github-repo-name>", from: "<version>")
    ]
    ```

    <Tip>
      与依赖集中式注册表的其他语言不同，Swift 包一旦被标记并推送到 Git 仓库就立即可用。

      您可以选择将您的包提交到社区维护的 [Swift Package Index](https://swiftpackageindex.com/) 以获得更好的可发现性。
    </Tip>
  </Step>
</Steps>