---
title: DittoSwiftTools
slug: v4-4/cvAxb9NJLrChaZRPtoViT
docTags: 
createdAt: 2023-10-02T17:48:12.599Z
---

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

## Requirements[​](https://legacydocs.ditto.live/ios/quick-tips/DittoSwiftTools#requirements)

- iOS 15.0+
- Swift 5.0+

## Installation[​](https://legacydocs.ditto.live/ios/quick-tips/DittoSwiftTools#installation)

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

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

![](https://api.archbee.com/api/optimize/qoRkNxW5fJ81r_NqVpc8C/2Un0KRmDsFm71VZgFQAAw_image.png)
:::

:::WorkflowBlockItem
Select "Add Package"
:::

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

:::hint{type="info"}
If you are looking for compatibility with Ditto v4, please target the [v4 branch](https://github.com/getditto/DittoSwiftTools/tree/v4) in the Swift Package Manager.
:::
::::
:::::

## Usage[​](https://legacydocs.ditto.live/ios/quick-tips/DittoSwiftTools#usage)

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

:::::WorkflowBlock
::::WorkflowBlockItem
### 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.

::Image[]{src="https://api.archbee.com/api/optimize/qoRkNxW5fJ81r_NqVpc8C/hEGlPl93Bip8Z1ClnxITU_image.png" size="54" width="303" height="516" position="flex-start" showCaption="false"}

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.

:::CodeblockTabs
Swift

```swift
import DittoPresenceViewer

struct PresenceViewer: View{

    var body: some View {
        PresenceView(ditto: DittoManager.shared.ditto)
    }
}
```
:::

**UIKit**

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

`DittoPresenceView(ditto:DittoManager.shared.ditto).viewController`&#x20;

:::CodeblockTabs
Swift

```swift
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    present(DittoPresenceView(ditto: DittoManager.shared.ditto).viewController, animated: true) {
        if let selected = tableView.indexPathForSelectedRow {
            tableView.deselectRow(at: selected, animated: true)
        }
    }
}
```
:::
::::

::::WorkflowBlockItem
### 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.

::Image[]{src="https://api.archbee.com/api/optimize/qoRkNxW5fJ81r_NqVpc8C/_ZaGOev7zJWf15O3KXqcd_image.png" size="46" width="347" height="450" position="flex-start" showCaption="false"}

**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.&#x20;

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.

:::CodeblockTabs
Swift

```swift
import DittoDataBrowser

struct DataBrowserView: View {
    var body: some View {
       DataBrowser(ditto: DittoManager.shared.ditto)
    }
}
```
:::

**UIKit**

Pass `DataBrowser(ditto: Ditto)` to a [UIHostingController](https://sarunw.com/posts/swiftui-in-uikit/) which will return a view controller that you can use to present.

:::CodeblockTabs
Swift

```swift
let vc = UIHostingController(rootView: DataBrowser(ditto: DittoManager.shared.ditto))

present(vc, animated: true)
```
:::
::::

::::WorkflowBlockItem
## Export Logs

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

::Image[]{src="https://api.archbee.com/api/optimize/qoRkNxW5fJ81r_NqVpc8C/Cr3L-KTIy8Jgap33QDdSU_image.png" size="64" width="403" height="346" position="flex-start" showCaption="false"}

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](https://developer.apple.com/documentation/swiftui/view/sheet\(ispresented\:ondismiss\:content:\)).

:::CodeblockTabs
Swift

```swift
.sheet(isPresented: $exportLogs) {
    ExportLogs()
}
```
:::

**UIKit**

Pass `ExportLogs()` to a [UIHostingController](https://sarunw.com/posts/swiftui-in-uikit/) which will return a view controller that you can use to present.

:::CodeblockTabs
Swift

```swift
let vc = UIHostingController(rootView: ExportLogs())

present(vc, animated: true)
```
:::
::::

:::WorkflowBlockItem
### Disk Usage

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

::Image[]{src="https://api.archbee.com/api/optimize/qoRkNxW5fJ81r_NqVpc8C/V9aX_dUson0LBAGCCKLIa_image.png" size="30" width="328" height="552" position="flex-start" showCaption="false"}

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

::Image[]{src="https://api.archbee.com/api/optimize/qoRkNxW5fJ81r_NqVpc8C/V9aX_dUson0LBAGCCKLIa_image.png" size="30" width="328" height="552" position="flex-start" showCaption="false"}

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
import DittoDiskUsage

struct DiskUsageViewer: View {
    var body: some View {
        DittoDiskUsageView(ditto: DittoManager.shared.ditto)
    }
}
```

**UIKit**

Pass `DittoDiskUsageView(ditto: Ditto)` to a [UIHostingController](https://sarunw.com/posts/swiftui-in-uikit/) which will return a view controller that you can use to present.

```swift
let vc = UIHostingController(rootView: DittoDiskUsageView(ditto: DittoManager.shared.ditto))

present(vc, animated: true)
```
:::
:::::

