How-To Tutorials
Swift

DittoSwiftTools

DittoSwiftTools are diagnostic tools for Ditto. You can view connected peers, export debug logs, browse collections (documents), and monitor Ditto's disk usage.

For the source code, see the GitHub > getditto > DittoSwiftTools repository.

Requirements

  • iOS 15.0+
  • Swift 5.0+

Installation

The recommended approach to using DittoSwiftTools in your project is using the Swift Package Manager.

1

With your project open in Xcode go to File -> Add Packages, then search using "github.com/getditto/DittoSwiftTools" to find the DittoSwiftTools package.

Document image

2

Select "Add Package"

3

Select which DittoSwiftTools products you would like, then select "Add Package"

If you are looking for compatibility with Ditto v4, please target the v4 branch in the Swift Package Manager.

Usage

There are four targets in this package: Presence Viewer, Data Browser, Export Logs, Disk Usage.

1

Presence Viewer

The Presence Viewer displays a mesh graph that allows you to see all connected peers within the mesh and the transport that each peer is using to make a connection.

Document image


First, make sure the DittoPresenceViewer was added to your Target. Then, use import DittoPresenceViewer to import the PresenceViewer.

You can use the Presence Viewer in SiwftUI or UIKit.

SwiftUI

Use PresenceView(ditto: Ditto) and pass in your Ditto instance to display the mesh graph.

Swift


UIKit

Call present, pass the following as a parameter, and then set animated to true:

DittoPresenceView(ditto:DittoManager.shared.ditto).viewController

Swift

2

Data Browser

The Ditto Data Browser allows you to view all your documents within each collection, including each document's fields. With the Data Browser, you can observe any changes that are made to your collections and documents in realtime.

Document image


Standalone App 

If you are using the Data Browser as a standalone app, there is a button, Start Subscriptions, you must press in order to start syncing data.

If you are embedding the Data Browser into another application then you do not need to press Start Subscriptions as you should already have your subscriptions running.

First, make sure the "DittoDataBrowser" was added to your Target. Then, use import DittoDataBrowser to import the Data Browser.

SwiftUI

Use DataBrowser(ditto: Ditto) and pass in your Ditto instance to display the Data Browser.

Swift


UIKit

Pass DataBrowser(ditto: Ditto) to a UIHostingController which will return a view controller that you can use to present.

Swift

3

Export Logs

Export Logs allows you to export a file of the logs from your app.

Document image


First, make sure the "DittoExportLogs" was added to your Target. Then, use import DittoExportLogs to import the export logs.

SwiftUI

Use ExportLogs() to export the logs. It is recommended to call ExportLogs from within a sheet.

Swift


UIKit

Pass ExportLogs() to a UIHostingController which will return a view controller that you can use to present.

Swift

4

Disk Usage

Disk Usage allows you to see Ditto's file space usage.

Document image


First, make sure the "DittoDiskUsage" was added to your Target. Then, use import DittoDiskUsage to import the Disk Usage.

Document image


First, make sure the "DittoDiskUsage" was added to your Target. Then, use import DittoDiskUsage to import the Disk Usage.

SwiftUI

Use DittoDiskUsageView(ditto: Ditto) and pass in your Ditto instance.

Swift


UIKit

Pass DittoDiskUsageView(ditto: Ditto) to a UIHostingController which will return a view controller that you can use to present.

Swift