To start using the Server Side Cloud Swift SDK, install Swift 6.2 or later via the swiftly CLI or prebuilt toolchains, then add google-cloud-swift dependencies to your Package.swift manifest for Linux or macOS development.


Installing the Swift Compiler
On Linux workstations, use the swiftly CLI installer to get the official Swift toolchain. Download the tarball for your architecture, extract it, initialize the environment, and source the env.sh file to make swift available in your shell. This method ensures you get a version-managed Swift installation suitable for server-side development.
Alternatively, download prebuilt toolchain tarballs directly from Swift.org for Ubuntu, Debian, Fedora, or Amazon Linux. After installation, verify your compiler meets the requirement by running swift --version and confirming it shows Swift 6.2 or later, as the google-cloud-swift SDK requires this minimum version.
To avoid Swift Package Manager bare repository warnings when cloning across Linux filesystems, configure Git globally with git config --global safe.bareRepository all before building your project. This step prevents SPM from blocking access to repositories during dependency resolution.
Setting Up Your IDE and Package Manifest
You can develop google-cloud-swift projects on Apple hardware using Xcode or on Linux workstations using Visual Studio Code. Both environments support Swift Package Manager and provide editing, debugging, and build integration for server-side Swift applications targeting Google Cloud services.
In your Package.swift manifest, add dependencies using the swift package add-dependency command. For example, to integrate the Natural Language API, run swift package add-dependency https://github.com/googleapis/swift-google-cloud-language-v2.git --from 0.4.0, then link the module to your target with swift package add-target-dependency GoogleCloudLanguageV2 CloudBackendService --package swift-google-cloud-language-v2.
On macOS, you must explicitly set the platforms directive in Package.swift to include .macOS(.v15) when targeting Apple silicon or Intel Macs. This directive is ignored by SPM on Linux targets, allowing a single manifest to work across both operating systems without modification.
Initializing and Using a Cloud Client
Once dependencies are resolved, initialize a service client in your code with no arguments to use Application Default Credentials. For example, let client = try LanguageServiceClient() automatically authenticates using ADC, service account keys, or Workload Identity Federation based on your environment configuration.
Structure API requests using builder closures to avoid mutable state. Configure a Document for sentiment analysis with Document().with { $0.type = .plainText; $0.source = .content(text) }, then call the async method client.analyzeSentiment(request:) and handle the response in a try await block to extract sentiment.score.
To override credentials programmatically, such as when using an API key, import GoogleCloudAuth and GoogleCloudGax, create Credentials(configuration: .apiKey(apiKey)), and pass it via ClientOptions().with { $0.credentials = credentials } when initializing the client, ensuring secure and explicit authentication control.
What to do next
Begin by installing Swift 6.2+, configuring your IDE, and adding the google-cloud-swift packages you need via Swift Package Manager. Test authentication with a default-initialized client using Application Default Credentials, then expand to explicit credential overrides as your deployment requires. Visit the official GitHub repository to explore generated clients for over 100 Google Cloud services.
FAQ
Do I need to install Swift differently on Linux versus macOS to use the google-cloud-swift SDK?
No, the SDK supports both platforms with the same Package.swift manifest. You can install Swift via swiftly or prebuilt toolchains on Linux, and use Xcode or the toolchain on macOS—no code changes are required between operating systems.
How does the google-cloud-swift SDK handle authentication by default?
By default, clients use Application Default Credentials (ADC), which automatically checks for GOOGLE_APPLICATION_CREDENTIALS, quota project settings, or the local gcloud CLI configuration to authenticate requests without hardcoding credentials in your code.
Can I use the google-cloud-swift SDK in Apple client apps like iOS or visionOS?
No, the Server Side Cloud Swift SDK is intended for server, container, and DevOps environments only. For client-side Apple apps, use the Firebase SDK for Apple Platforms to avoid embedding service account credentials in user-facing binaries.
Source: Introducing the Server Side Cloud Swift SDK (GCP).



