---
url: https://talkjs.com/docs/Data_APIs/Swift/
title: "Swift Data API | Swift | TalkJS Documentation"
---

For AI agents: Find a documentation index at https://talkjs.com/llms.txt (full content at https://talkjs.com/llms-full.txt). Get a markdown version of any page by appending .md to its URL path.

# Swift Data API

Connect to chat data as a user.

The Swift Data API lets you connect to TalkJS as a user and read, subscribe to, and update chat data from Swift-based environments. It's available through the TalkJS Core (`talkjs-core-swift`) Swift package on [GitHub](https://github.com/talkjs/talkjs-core-swift).

The Data API is primarily intended for client environments such as iOS apps, because it connects as a single specific user.

If you need server-side access to all conversations or users, use the [REST API](https://talkjs.com/docs/REST_API/) instead.

## Requirements

To use the Swift Data API, your project needs to have the following:

-   Swift 6.3+
-   For iOS apps: iOS 15+
-   For macOS apps: macOS 11+

## Installation

To add the TalkJS Core package to your project using Swift Package Manager:

-   In Xcode, choose **File > Add Package Dependencies...**, enter `https://github.com/talkjs/talkjs-core-swift`, and add the `talkjs-core-swift` library to your app target.
-   If you use a `Package.swift` file, add the package as a dependency and the `talkjs-core-swift` library to your target:

```swift
dependencies: [
  .package(url: "https://github.com/talkjs/talkjs-core-swift", from: "<latest_version>"),
],
targets: [
  .target(
    name: "<YOUR_TARGET>",
    dependencies: [
      .product(name: "talkjs-core-swift", package: "talkjs-core-swift"),
    ]
  ),
]
```

Replace `<latest_version>` with the latest available version, for example `0.0.3`. You can check the GitHub tags for the [latest version](https://github.com/talkjs/talkjs-core-swift/tags).

## Create a TalkJS session

To use the Swift Data API, import the `talkjs_core_swift` module.

To connect as a user, create a TalkJS session using [getTalkSession](https://talkjs.com/docs/Data_APIs/Swift/TalkSession/):

```swift
import talkjs_core_swift

let session = getTalkSession(
  appId: "<APP_ID>", // Replace with your own app ID
  userId: "<USER_ID>" // Replace with a user ID
)
```

Replace:

-   `<APP_ID>` with your TalkJS app ID. You can find your app ID on the **Settings** page of your [TalkJS dashboard](https://talkjs.com/dashboard/).
-   `<USER_ID>` with the [ID of the user](https://talkjs.com/docs/Concepts/Users/#user-id) you want to connect as.

Once connected, the session allows you to retrieve conversations, send messages, and subscribe to real-time updates.
