# Quickstart

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

Show a Mountaya map with the Tour du Mont-Blanc on it in a SwiftUI iPhone app.

A SwiftUI app for iPhone that shows a topographic map and draws the Tour du Mont-Blanc on it.

## Before you start

You need Xcode with Swift 6.2.3 or newer, an iOS 17 simulator or device, and a publishable key with the `tiles` and `publishing` scopes from **Organization → API keys** in the [Mountaya app](https://app.mountaya.com/api-keys).

## Install

Create an iOS App project in Xcode with SwiftUI. Choose **File → Add Package Dependencies**, paste `https://github.com/mountaya/sdk-swift`, and add `MountayaClient`, `MountayaGeo` and `MountayaElements` to the app target. Then turn on the package's **Elements** trait under **Package Dependencies** in the project settings.

## Add your key

Add a `Local.xcconfig` that git ignores, set it as the target's configuration file, and pass the key to Info.plist:

```text
MOUNTAYA_PUBLISHABLE_KEY = pk_your_publishable_key
```

```xml
<key>MOUNTAYA_PUBLISHABLE_KEY</key>
<string>$(MOUNTAYA_PUBLISHABLE_KEY)</string>
```

## Show the map

Replace the app's Swift file with this:

```swift
import Foundation
import MountayaClient
import MountayaElements
import SwiftUI

@main
struct TrailApp: App {
  @State private var map = TrailApp.makeMap()

  var body: some Scene {
    WindowGroup {
      if let map {
        TrailMap(map: map)
      } else {
        Text("Set MOUNTAYA_PUBLISHABLE_KEY in Local.xcconfig.")
      }
    }
  }

  // A map engine over a client that holds the key from Info.plist.
  static func makeMap() -> MapEngine? {
    let key = Bundle.main.object(forInfoDictionaryKey: "MOUNTAYA_PUBLISHABLE_KEY") as? String
    guard let key, let mountaya = try? Mountaya(credential: .publishable(key: key)) else {
      return nil
    }
    return MapEngine(client: mountaya)
  }
}

struct TrailMap: View {
  let map: MapEngine

  var body: some View {
    MapView(map)
      .ignoresSafeArea()
      .task { try? await map.setTerrain() }
  }
}
```

`MapEngine` holds what the map shows, and `MapView` draws it.

## Draw an itinerary

Replace `TrailMap` with this version. It draws the itinerary and fits the camera to it:

```swift
import MountayaElements
import MountayaGeo
import SwiftUI

struct TrailMap: View {
  let map: MapEngine

  var body: some View {
    MapView(map)
      .ignoresSafeArea()
      .task {
        try? await map.setTerrain()
        _ = try? await map.setItinerary(
          "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21", fit: CameraFit(padding: PixelPadding(48)))
      }
  }
}
```

## Run it

Run the app on an iPhone simulator. The map opens on the Tour du Mont-Blanc, with the Mountaya watermark in its top-left corner.

- The sample app Trail, under `Examples/Trail` in the SDK repository, is the complete version of this quickstart: controls, search, the profile, the tables and navigation. Run it from `Trail.xcodeproj` after copying `Config/Local.xcconfig.example` to `Config/Local.xcconfig`.
- `setTerrain()` shows the first terrain of the Tile API's catalogue, light until `setTerrainVariant(.dark)`. `setTerrain("<slug>")` names another.
- `setItinerary(_:fit:)` draws one itinerary by id in its own slot; a later call replaces it, and one that answers after a later call answers `false`. Cancelling its task (SwiftUI's `.task` does when the view goes away) withdraws it. `clearItinerary()` removes it.
- The key needs the `tiles` scope to draw the map, and `publishing` to read the published itinerary. `PixelPadding` and the camera's rules are `MountayaGeo`'s, which is why the app links it. A refused key shows as `state.isAccessRequired` and an `.accessRefused` event; see [show a map](https://docs.mountaya.com/en/sdks/swift/map.md#errors).
- Every request MapLibre makes for the map (style, tiles, sprites, glyphs) carries the client's credential, its language and `X-Mountaya-Client`, and only to the Tile API's host.
- The watermark shows unless the organization holds white label; the map reads that once per key.
- A key missing from Info.plist reads as `nil` here; a key Info.plist holds empty (`$(MOUNTAYA_PUBLISHABLE_KEY)` unset) reads as `""`, which `Mountaya(credential:)` refuses, so `makeMap()` answers nil either way.

## Next steps

- [Show a map](https://docs.mountaya.com/en/sdks/swift/map.md): The camera, events, layers and waypoints.
- [Controls and panels](https://docs.mountaya.com/en/sdks/swift/controls.md): Zoom, layers, points of interest and units.
