Installation

Add SwiftDataServer to your Swift package and configure your preferred database backend.

Package.swift

Add SwiftDataServer as a dependency in your Package.swift:

dependencies: [
    .package(
        url: "https://packages.swiftdataserver.com/YOUR_TOKEN/SwiftDataServer.git",
        from: "1.0.0"
    )
]

Then add the products you need to your target:

targets: [
    .target(
        name: "App",
        dependencies: [
            .product(name: "SwiftDataServer", package: "SwiftDataServer"),
            .product(name: "PostgreSQLBackend", package: "SwiftDataServer"),  // or MySQLBackend, SQLiteBackend
            .product(name: "VaporIntegration", package: "SwiftDataServer"),   // optional
        ]
    )
]

Available Products

Product Description
SwiftDataServer Core library with models, contexts, and queries
PostgreSQLBackend PostgreSQL database driver
MySQLBackend MySQL database driver
SQLiteBackend SQLite database driver
VaporIntegration Vapor framework extensions

Importing in Shared Code

If you're sharing models between iOS/macOS and server, use conditional imports:

#if canImport(SwiftData)
import SwiftData        // iOS/macOS
#else
import SwiftDataServer  // Linux/Server
#endif

Note for macOS server development: If running your server on macOS where SwiftData is available, use a compilation flag to distinguish server builds:

#if canImport(SwiftData) && !SERVER
import SwiftData
#else
import SwiftDataServer
#endif

Add the flag in Package.swift: .target(name: "Server", swiftSettings: [.define("SERVER")])

Access Token

Your access token is available in your dashboard after purchasing a license. The token authenticates your package manager with our private package registry.

Next Steps