# Install and set up

> Canonical URL: https://docs.mountaya.com/en/sdks/swift/install/
> Last updated: 2026-11-27
> Rules for agents: https://docs.mountaya.com/llms.txt#rules-for-agents

Add the Swift package, turn on the Elements trait for a map, and read your publishable key from Info.plist.

The Swift SDK is one Swift package. You add it once and name the products each target links.

## Install the packages

In an Xcode project, choose **File → Add Package Dependencies**, paste `https://github.com/mountaya/sdk-swift`, and pick the products for your app target.

In a package your app links, depend on it in `Package.swift` and list the products each library target uses:

```swift
// swift-tools-version: 6.2
import PackageDescription

let package = Package(
  name: "TrailKit",
  platforms: [.iOS(.v17), .macOS(.v14)],
  products: [.library(name: "TrailKit", targets: ["TrailKit"])],
  dependencies: [
    .package(url: "https://github.com/mountaya/sdk-swift", from: "0.1.0", traits: ["Elements"])
  ],
  targets: [
    .target(
      name: "TrailKit",
      dependencies: [
        .product(name: "MountayaClient", package: "sdk-swift"),
        .product(name: "MountayaGeo", package: "sdk-swift"),
        .product(name: "MountayaElements", package: "sdk-swift"),
      ]
    )
  ]
)
```

- The URL is the public, read-only GitHub mirror; each release is a tag there. Depend `from:` the release you wrote against, `0.1.0` today.
- One tag versions `MountayaClient`, `MountayaAdmin`, `MountayaGeo`, `MountayaNavigation` and `MountayaElements` together. Name only the products a target links: SwiftPM links nothing else.
- An iOS app is an Xcode app target; SwiftPM builds no iOS app on its own, so a package holds the app's library targets. A server is an `.executableTarget` that names `MountayaClient` and `MountayaAdmin`, never `MountayaElements`. An app never names `MountayaAdmin`.
- The package builds in the Swift 6 language mode. Its tools version is 6.2.3, so a consumer needs Swift 6.2.3 or newer; the `traits:` argument needs a consumer manifest at tools 6.1 or newer.
- `MountayaNavigation` needs no trait: it links nothing beyond the platform's own frameworks.

## Set up the platform

The map's view draws with MapLibre Native, which the package links only when you turn on its `Elements` trait. In a manifest, that is `traits: ["Elements"]` above. In Xcode, select the package under **Package Dependencies** in the project settings and turn on **Elements** in its traits.

Without the trait, or on a platform other than iOS, the compiler refuses `MapView` and says what to turn on. An app that shows no map leaves the trait off and resolves no MapLibre.

- `Elements` is off by default. A dependency a trait disables is left out of resolution, so a consumer without it downloads no MapLibre binary.
- With the trait on, SwiftPM resolves MapLibre Native in `7.0.0..<8.0.0`. Xcode records the trait on the package reference as `traits = ( Elements, );` in the project file.
- `MapView` and every SwiftUI view of `MountayaElements` (controls, panels, `SearchControl`, `ItineraryProfile`, the tables, `ItinerarySparkline`, `WaypointCard`, `Glyph`) compile only where `Elements && os(iOS) && !targetEnvironment(macCatalyst)`. Without the trait the diagnostic tells you to depend on the package with `traits: ["Elements"]`; off iOS it tells you to hold the map's state with `MapEngine`.
- `MapEngine` and the rest of `MountayaElements` build on every platform, for an app that draws its own map or a test.
- An app that reads the device's position declares `NSLocationWhenInUseUsageDescription` in its Info.plist and asks for access itself; [navigation](https://docs.mountaya.com/en/sdks/swift/navigation.md#location) covers it.

## Add your key

An app carries a publishable key. Keep it out of git: put it in a `Local.xcconfig` that git ignores, and let the build write it into your Info.plist.

```text
// Config/Local.xcconfig, included by your target's .xcconfig
MOUNTAYA_PUBLISHABLE_KEY = pk_your_publishable_key
```

```xml
<!-- Info.plist -->
<key>MOUNTAYA_PUBLISHABLE_KEY</key>
<string>$(MOUNTAYA_PUBLISHABLE_KEY)</string>
```

The app reads it from its bundle:

```swift
import Foundation
import MountayaClient

let key = Bundle.main.object(forInfoDictionaryKey: "MOUNTAYA_PUBLISHABLE_KEY") as? String ?? ""
let mountaya = try Mountaya(credential: .publishable(key: key))
```

A server reads its keys from the environment instead:

```swift
import Foundation
import MountayaClient

let environment = ProcessInfo.processInfo.environment
let mountaya = try Mountaya(credential: .secret(key: environment["MOUNTAYA_SECRET_KEY"] ?? ""))
```

Create both keys under **Organization → API keys** in the [Mountaya app](https://app.mountaya.com/api-keys).

- The pattern is the sample app Trail's: `Config/Local.xcconfig` (gitignored, copied from `Local.xcconfig.example`) is included by the target's xcconfig, the build substitutes `$(MOUNTAYA_PUBLISHABLE_KEY)` into Info.plist, and the app reads it once at launch. An environment variable of the same name set in the scheme can stand over it.
- Trail reads two more settings the same way: `MOUNTAYA_ITINERARY_ID` and `MOUNTAYA_SESSION_URL` (where the app posts for a session token). An xcconfig reads `//` as a comment, so a URL is written `https:/$()/example.com/session`.
- A key the Mountaya app issues is its prefix (`pk_`, `sk_`) and 32 lowercase hex characters; the client checks the prefix where it is built. A publishable key ships in apps; a secret key mints session tokens on a server and never reaches a device.
- `Mountaya(credential:)` refuses a credential no request could carry where the client is built, an empty key included, with a `MountayaError.configuration`.
- Scopes: `tiles` draws the map, `publishing` reads published itineraries, `data` calls the Data API (with a session token beside a publishable key), `studio-embedded` acts as a member. A publishable key carries no `management`.

## Import the right package

| To | Import |
| --- | --- |
| Call the APIs | `MountayaClient` |
| Mint session tokens, manage an organization, verify webhooks (servers only) | `MountayaAdmin` |
| Format distances, read terrain, build a profile | `MountayaGeo` |
| Follow a route on the device | `MountayaNavigation` |
| Show a map and its elements | `MountayaElements` |

The secret key and the admin product are for servers. An iOS build cannot name `.secret(key:)` at all.

- Every product re-exports nothing: a file imports each module whose names it uses, and with `MemberImportVisibility` on it must. `RestSchema`, `DataSchema` and `TileSchema` are `MountayaClient`'s; `AdminSchema` and `WebhookEvent` are `MountayaAdmin`'s.
- `.secret(key:)`, `Credential(secretKey:…)` and `constructWebhookEvent` are unavailable on iOS, iPadOS, tvOS, watchOS, visionOS and Mac Catalyst: "A secret key belongs on a server, never in an app." They exist on macOS and Linux.
- `import MountayaAdmin` adds `admin` to the core's `Mountaya`; there is no second client type.
- The session a server mints is the core's `RestSchema.Session`, which the app reads without linking the admin unit.

## Next steps

- [Quickstart](https://docs.mountaya.com/en/sdks/swift/quickstart.md): A map with an itinerary in a SwiftUI app.
- [Server quickstart](https://docs.mountaya.com/en/sdks/swift/quickstart-server.md): Mint a session token and call the Data API.
