This tutorial will walk you through setting up a basic sample app created using the PubNub Swift Chat SDK, explaining the architecture behind the app and how the code works. The devrel team has developed the Swift Chat SDK sample that will be used for this tutorial, which can be found at https://github.com/PubNubDevelopers/Chat-SDK-Tutorial-Swift and is released under MIT. The sample is designed for illustrative purposes only and has minimal error handling.

Prerequisites

The Swift Chat SDK is UI and framework-agnostic, allowing you complete control over how your application looks and how it is architected. The sample application has been written with SwiftUI with some custom styling.

Make sure you have the following installed on your computer:

  • Xcode (At the time of writing, the latest version is 16.0, but any recent version should suffice)
  • Git

Download the Source Application

In a terminal or command window, navigate to an empty folder. Enter the following command to clone the repository.

1 git clone https://github.com/PubNubDevelopers/Chat-SDK-Tutorial-Swift.git

This step is optional but will ensure that the version of the repository you are using matches the version used to create this tutorial.

1 git checkout 27d6bc09a5ce683269d7eb841f24aba013f62d02

Install dependencies

Open the Chat-SDK-Tutorial-Swift/PubNubSwiftChatSDKTutorial folder in Xcode. This should automatically download the required package dependencies.

Tutorial - Swift Chat SDK - Package Dependencies

We strive to maintain up-to-date instructions for all our tutorials, but if you experience build issues - especially upgrading the sample to newer versions of our SDK, please contact our DevRel team at devrel@pubnub.com.

Open the following file:

/PubNubSwiftChatSDKTutorial/PubNubSwiftChatSDKTutorial/Keys.swift

The file currently contains placeholders for your PubNub publish and subscribe keys:

1 2 3 4 5 // REPLACE THESE WITH YOUR PUB / SUB KEYS struct Keys { static let PUBNUB_PUBLISH_KEY="YOUR_PUBLISH_KEY_HERE" static let PUBNUB_SUBSCRIBE_KEY="YOUR_SUBSCRIBE_KEY_HERE" }

The next step is to generate your own publish and subscribe keys to replace these placeholders.

BackStep 1 of 4Next