Get started
Swift SDK
Get started

Install and set up

Install and set up

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-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"),
      ]
    )
  ]
)

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.

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.

// Config/Local.xcconfig, included by your target's .xcconfig
MOUNTAYA_PUBLISHABLE_KEY = pk_your_publishable_key
<!-- Info.plist -->
<key>MOUNTAYA_PUBLISHABLE_KEY</key>
<string>$(MOUNTAYA_PUBLISHABLE_KEY)</string>

The app reads it from its bundle:

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:

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.

Import the right package

ToImport
Call the APIsMountayaClient
Mint session tokens, manage an organization, verify webhooks (servers only)MountayaAdmin
Format distances, read terrain, build a profileMountayaGeo
Follow a route on the deviceMountayaNavigation
Show a map and its elementsMountayaElements

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

Next steps

Last updated