---
title: Installing Swift SDK
slug: v4-4/swift-installing
docTags: 
createdAt: 2023-07-28T20:16:57.748Z
---

You can integrate the Ditto SDK into Swift projects to develop native apps for Apple iOS and macOS platforms.&#x20;

:::hint{type="info"}
For a complete overview of the platforms, transports, and devices the Kotlin SDK supports, see [Compatibility with Swift](docId\:gMw3Z9o8MJMZNvdTjWeJV).
:::

:::hint{type="info"}
Ditto does not offer native support for apps developed in Objective-C.&#x20;

If you want to use the Ditto SDK for Swift with an Objective-C app, you must use a bridge to integrate.

For a code walkthrough on how to create a bridge that calls into Swift from Objective-C, see the getditto > [example-swift-bridge-to-objectivec](https://github.com/getditto/example-swift-bridge-to-objectivec) repository in GitHub.
:::

To install the Ditto SDK and start syncing offline:

::::WorkflowBlock
:::WorkflowBlockItem
Confirm that you meet the minimum requirements. ([Prerequisites](./#prerequisites))
:::

:::WorkflowBlockItem
Install the necessary dependencies. ([Adding Package Dependencies](./#adding-package-dependencies))
:::

:::WorkflowBlockItem
Set up your app permissions. ([Configuring Permissions](./#configuring-permissions))
:::

:::WorkflowBlockItem
Authenticate with the Big Peer and then start syncing offline. ([Integrating and Initializing Sync](./#integrating-and-initializing-sync))
:::
::::

# Prerequisites

Following are the minimum requirements that must be met before attempting to install Ditto.

- iOS version 13.0
- macOS version 11.0

# Adding Package Dependencies

:::::::Tabs
::::::Tab{title="Swift Package Manager"}
From your project in Xcode:

:::::WorkflowBlock
:::WorkflowBlockItem
Click **File** and then select **Add Packages...** from the menu.
:::

::::WorkflowBlockItem
In the **Recently Used&#x20;**&#x64;ialog box, copy-paste the following URL into the search box located in the upper right corner.

[https://github.com/getditto/DittoSwiftPackage](https://github.com/getditto/DittoSwiftPackage)

:::hint{type="info"}
For more information, see the official Apple documentation > [Adding package dependencies to your app](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app#3512138).
:::

::Image[]{src="https://api.archbee.com/api/optimize/qoRkNxW5fJ81r_NqVpc8C/CPLC4zUviQrH3N9FtU7AO_dependency-install-1.png" size="74" width="1190" height="787" position="flex-start" showCaption="false"}
::::

:::WorkflowBlockItem
Click to select **DittoObjC&#x20;**&#x61;nd **DittoSwift** > and then click **Add Package**.&#x20;

::Image[]{src="https://api.archbee.com/api/optimize/qoRkNxW5fJ81r_NqVpc8C/uc85HAnzvQ1ukZT-BnoZZ_image.png" size="74" width="655" height="297" position="flex-start" showCaption="false"}
:::
:::::
::::::

:::::Tab{title="CocoaPods"}
Before installing Ditto using CocoaPods dependency manager, do the following:

::::WorkflowBlock
:::WorkflowBlockItem
Make sure you have CocoaPods version 1.1.0 or later installed. For installation and upgrade instructions, see the official CocoaPods [Getting Started](https://guides.cocoapods.org/using/getting-started.html#installation) Guide.
:::

:::WorkflowBlockItem
In your project's Podfile, add the line `use_frameworks!`to indicate that you want to use dynamic frameworks for the pods you're integrating.
:::

:::WorkflowBlockItem
Add the DittoSwift framework with version 4.3.0 by running the following in your project directory:

```none
pod 'DittoSwift', '=4.3.0'
```
:::

:::WorkflowBlockItem
Run the following to install the latest version of the dependencies:

```none
pod install --repo-update
```
:::
::::
:::::
:::::::

# Configuring Permissions

Once you've added dependencies:

::::::WorkflowBlock
::::WorkflowBlockItem
From Xcode, add a new **Custom iOS Target Properties** entry:

1. From the left navigator area, click your project.
2. In the editor that appears, click **Info** tab.
3. Right-click any row in the list, and then select **Add Row** from the menu.

:::hint{type="info"}
For instructions on configuring permissions for your app, see the [Installing Swift SDK](docId\:R9r027a8PWDBtdNL_NfK3) > [Configuring Permissions](./#configuring-permissions) topic.
:::

::Image[]{src="https://api.archbee.com/api/optimize/qoRkNxW5fJ81r_NqVpc8C/Ndgl7gVXr1LJ0-s8tApoL_image.png" size="74" width="2102" height="886" position="flex-start" showCaption="false"}
::::

:::::WorkflowBlockItem
From your project's `Info.plist`file, add the following key-value pairs, and then, if applicable, modify each string assigned to `Value`:

- Once implemented, the following string values display as a prompt to your end users explaining why the app requires certain permissions.&#x20;

- If your end users prefer a language other than English, replace the string values with their language equivalents.

::::Tabs
:::Tab{title="From Info Tab"}
```none
Key: NSBluetoothAlwaysUsageDescription
Type: String
Value: Uses Bluetooth to connect and sync with nearby devices

Key: NSLocalNetworkUsageDescription
Type: String
Value: Uses WiFi to connect and sync with nearby devices

Key: NSBonjourServices
Type: String
Value: _http-alt._tcp.
```
:::

:::Tab{title="From Source Code"}
```xml
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Uses Bluetooth to connect and sync with nearby devices</string>
<key>NSLocalNetworkUsageDescription</key>
<string>Uses WiFi to connect and sync with nearby devices</string>
<key>NSBonjourServices</key>
<array>
  <string>_http-alt._tcp.</string>
</array>
```
:::
::::
:::::

:::WorkflowBlockItem
From Xcode, ensure your app continues to sync while it runs in the background, as well as when the end-user device is locked by enabling **Bluetooth Background Modes**:

1. From the left navigator area, click your project.

2. Click **Signing & Capabilities**.
   &#x20;
3. From **TARGETS**, select your app from the list.&#x20;

4. From **Background Modes**, click to select **Uses Bluetooth LE** **accessories** from the list.

![](https://api.archbee.com/api/optimize/qoRkNxW5fJ81r_NqVpc8C/xZM46JSazTEjeIQJnl23f_ble-background-permission.png)
:::
::::::

# Integrating and Initializing Sync

Once you've set up your environment, import the Ditto SDK in your codebase and obtain your access credentials.

:::hint{type="warning"}
Unless you have a specialized use case, such as a government app, you must connect to the internet at least once before you can sync offline with other peers.&#x20;

For more information, see *Ditto Basics&#x20;*> [Authentication and Initialization](docId\:c802C1qiAkfgA2QxmcyWu).
:::

:::::WorkflowBlock
:::WorkflowBlockItem
From the top-most scope of your app's codebase, add the following to set up authentication and start syncing offline.
:::

::::WorkflowBlockItem
Replace `YOUR_APP_ID` and `YOUR_PLAYGROUND_TOKEN` with your access credentials available from the portal.&#x20;

:::hint{type="info"}
For instructions on how to obtain your access credentials, see [Onboarding](docId\:JQjYL9gbvsgI9vlW3Ywvc). For an introduction to authentication in Ditto, see *Ditto Basics* > [Authentication and Initialization](docId\:c802C1qiAkfgA2QxmcyWu).
:::

```swift
let ditto = Ditto(identity: .onlinePlayground(
    appID: "YOUR_APP_ID",
    token: "YOUR_PLAYGROUND_TOKEN"
))

do {
  try ditto.startSync()
} catch (let err) {
  print(err.localizedDescription)
}
```
::::
:::::

