Get Started
Install Guides

Swift

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

To install the Ditto SDK and start syncing offline:

1

Confirm that you meet the minimum requirements. (Prerequisites)

2

Install the necessary dependencies. (Adding Package Dependencies)

3

Set up your app permissions. (Configuring Permissions)

4

Authenticate with the Big Peer and then start syncing offline. (Integrating and Initializing Sync)

Prerequisites

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

  • iOS version 14
  • macOS version 11

Adding Package Dependencies

Swift Package Manager
CocoaPods

From your project in Xcode:

1

Click File and then select Add Packages... from the menu.

2

In the Recently Used dialog box, copy-paste the following URL into the search box located in the upper right corner.

For more information, see the official Apple documentation > Adding package dependencies to your app.

Document image

3

Click to select DittoObjC and DittoSwift > and then click Add Package.

Document image


Configuring Permissions

Once you've added dependencies:

1

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.

For instructions on configuring permissions for your app, see Authentication.

Document image

2

From your project's Info.plistfile, 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.
  • If your end users prefer a language other than English, replace the string values with their language equivalents.

Setting the Data Protection entitlement to NSFileProtectionComplete may lead to a crash.

To mitigate the crash, set the Data Protection entitlement to NSFileProtectionCompleteUntilFirstUserAuthentication.

From Info Tab
From Source Code
Text

3

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.
  3. Click + Capability and then, from the modal that appears, search and select Background Modes.
  4. From TARGETS, select your app from the list.
  5. From Background Modes, click to select the following:
    • Uses Bluetooth LE accessories
    • Acts as a Bluetooth LE accessory
Document image


Integrating and Initializing Sync

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

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.

For more information, see Ditto Basics > Authentication and Initialization.

1

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

2

Replace YOUR_APP_ID and YOUR_PLAYGROUND_TOKEN with your access credentials available from the portal.

For instructions on how to obtain your access credentials, see Get Started. For an introduction to authentication in Ditto, see Ditto Basics > Authentication and Initialization.

Swift




Updated 02 Apr 2024
Did this page help you?