# iOS (Swift) SDK Quickstart


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

{{< version-badge registry="github-tag" package="rudderlabs/rudder-sdk-swift" label="Swift Package Manager" fallback="1.3.0" href="https://github.com/rudderlabs/rudder-sdk-swift" >}}

## Prerequisites

- You must have **Xcode** installed on your system.
- Sign up for [RudderStack](https://app.rudderstack.com/signup).
- Set up a new [iOS (Swift) source](https://www.rudderstack.com/docs/dashboard-guides/sources/#adding-a-source) in the RudderStack dashboard and note its {{< glossary_tooltip "write-key" >}}.
- You will also need the {{< glossary_tooltip "data-plane-url" >}} associated with your RudderStack workspace.

## Platform support

The iOS (Swift) SDK supports the following platforms:

| Platform | Version |
| :----| :----|
| iOS | 15.0+ |
| macOS | 12.0+ |
| tvOS | 15.0+ |
| watchOS | 8.0+ |

## Step 1: Install iOS (Swift) SDK

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

- [Add Swift Package Manager (SPM) dependency](#add-swift-package-manager-dependency)
- [Add to `Package.swift`](#add-to-package-swift)

### Add Swift Package Manager dependency

1. In Xcode, select **File > Add Package Dependencies...**.

{{< image src="images/event-stream-sources/swift/add-package-dependencies.webp"  >}}

2. Enter the below package repository URL in the search bar:

```text
https://github.com/rudderlabs/rudder-sdk-swift
```

{{< image src="images/event-stream-sources/swift/search-package-url.webp"  >}}

3. Select the version to use (the latest version is recommended).
4. Select the project to which to add the package.
5. Click **Add Package**.

{{< image src="images/event-stream-sources/swift/add-swift-package.webp"  >}}

### Add to `Package.swift`

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

```swift
// 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 iOS (Swift) SDK

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

{{< tabs tabTotal="2" >}}
{{% tab tabName="Swift" %}}
```swift
// Import statement
import RudderStackAnalytics

// Initialize the RudderStack Analytics SDK
let config = Configuration(
    writeKey: "<WRITE_KEY>",
    dataPlaneUrl: "<DATA_PLANE_URL>"
)

let analytics = Analytics(configuration: config)
```
{{% /tab %}}
{{% tab tabName="Objective-C" %}}
```objectivec
// Import statement
@import RudderStackAnalytics;

// Initialize the RudderStack Analytics SDK
RSSConfigurationBuilder *builder = [[RSSConfigurationBuilder alloc]
    initWithWriteKey:@"<WRITE_KEY>"
    dataPlaneUrl:@"<DATA_PLANE_URL>"];

RSSAnalytics *analytics = [[RSSAnalytics alloc]
    initWithConfiguration:[builder build]];
```
{{% /tab %}}
{{< /tabs >}}

Replace the `WRITE_KEY` and `DATA_PLANE_URL` parameters with the iOS (Swift) source write key and the data plane URL obtained in [Prerequisites](#prerequisites).

## Step 3: Identify users

You can use the [`identify`]({{< ref "event-spec/standard-events/identify.md" >}}) 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:

{{< tabs tabTotal="2" >}}
{{% tab tabName="Swift" %}}
```swift
self.analytics.identify(
	userId: "1hKOmRA4el9Zt1WSfVJIVo4GRlm",
	traits: [
		"name": "Alex Keener",
		"email": "alex@example.com"
	]
)
```
{{% /tab %}}
{{% tab tabName="Objective-C" %}}
```objectivec
[self.client identify:@"1hKOmRA4el9Zt1WSfVJIVo4GRlm"
    traits:@{@"name": @"Alex Keener", @"email": @"alex@example.com"}];
```
{{% /tab %}}
{{< /tabs >}}

## Step 4: Track user actions

The [`track`]({{< ref "event-spec/standard-events/track.md" >}}) 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:

{{< tabs tabTotal="2" >}}
{{% tab tabName="Swift" %}}
```swift
self.analytics.track(
	name: "Order Completed", 
	properties: [
		"revenue": 30.0, 
		"currency": "USD"
	]
)
```
{{% /tab %}}
{{% tab tabName="Objective-C" %}}
```objectivec
[self.analytics track:@"Order Completed" 
	properties:@{@"revenue": @30.0, @"currency": @"USD"}];
```
{{% /tab %}}
{{< /tabs >}}

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.

<br />
