Swift SDK Quickstart

Install and use the RudderStack Swift SDK on your iOS, macOS, tvOS, and watchOS apps.

This guide will walk you through setting up the SDK and sending your first events to RudderStack.

Prerequisites

Platform support

The Swift SDK supports the following platforms:

PlatformVersion
iOS15.0+
macOS12.0+
tvOS15.0+
watchOS8.0+

Step 1: Install Swift SDK

Github Badge

RudderStack provides the following two options to integrate the RudderStack Swift SDK into your project:

Add Swift Package Manager dependency

  1. In Xcode, select File > Add Package Dependencies….
  1. Enter the below package repository URL in the search bar:
https://github.com/rudderlabs/rudder-sdk-swift
  1. Select the version to use (the latest version is recommended).
  2. Select the project to which to add the package.
  3. Click Add Package.

Add to Package.swift

Alternatively, you can add the dependency to your Package.swift file, as shown:

// swift-tools-version:5.9
import PackageDescription

let package = Package(
    name: "YourApp",
    dependencies: [
        .package(url: "https://github.com/rudderlabs/rudder-sdk-swift.git", from: "1.0.0")
    ],
    targets: [
        .target(
            name: "YourApp",
            dependencies: [
                .product(name: "RudderStackAnalytics", package: "rudder-sdk-swift")
            ]),
    ]
)

Step 2: Initialize Swift SDK

Before tracking any events, initialize the Swift SDK, as shown:

Replace the WRITE_KEY and DATA_PLANE_URL parameters with the Swift source write key and the data plane URL obtained in Prerequisites.

Step 3: Identify users

You can use the identify event to identify a user and associate them with their actions. It also enables you to record any traits about them like their name, email, etc.

You can use the identify method as follows:

Step 4: Track user actions

The track call lets you record the customer events, that is, the actions that they perform, along with any properties associated with them.

A sample track call is shown:

In the above snippet, the track method logs an event called Order Completed along with two event properties revenue and currency that provide additional context to the event.



Questions? Contact us by email or on Slack