Contents

alex566/DataScoutCompanion

Embeddable SwiftData Inspector

πŸ“¦ Installation

Add DataScoutCompanion to your project:

  1. In Xcode, choose File > Add Package Dependencies...
  2. Enter the repository URL:
https://github.com/alex566/DataScoutCompanion.git
  1. Set the version requirement.
  2. Add the DataScoutCompanion package to your app target.

🎯 Usage

Everything you need to do is present DatabaseBrowser:

import SwiftUI
import DataScoutCompanion

struct YourRootView: View {
    @State private var isBrowserPresented = false

    var body: some View {
        YourContentView()
            .toolbar {
                Button(action: { isBrowserPresented = true }) {
                    Image(systemName: "tablecells")
                }
            }
            .sheet(isPresented: $isBrowserPresented) {
                DatabaseBrowser()
            }
    }
}

πŸ›œ Remote debugging

  1. Update Info.plist with the following keys:
    <key>NSBonjourServices</key>
    <array>
        <string>_datascout-sync._tcp</string>
    </array>
    <key>NSLocalNetworkUsageDescription</key>
    <string>To debug the database over the local network</string>
  1. In your app’s startup code (e.g. in AppDelegate or SceneDelegate), import the package and call startAdvertising:
import DataScoutCompanion

func application(_ application: UIApplication,
                didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Option A: Pass an existing ModelContainer
    let myModelContainer = /* your ModelContainer instance */
    ConnectionService.shared.startAdvertising(container: myModelContainer)

    // Option B: Pass a file URL to your database
    let dbURL: URL = /* URL to your .sqlite3 file */
    ConnectionService.shared.startAdvertising(url: dbURL)

    return true
}

3. Use the Built-In Database Browser (Alternative)

If you’d rather broadcast from within the companion UI in your app:

  1. Open the database you wish to debug.
  2. Go to the Network Debugging menu.
  3. Enable the Discovery checkbox for that database.

Package Metadata

Repository: alex566/DataScoutCompanion

Stars: 108

Forks: 4

Open issues: 0

Default branch: main

Primary language: swift

License: MIT

Topics: coredata, ios, sqlite, swiftdata, swiftui

README: README.md