Installation
Add SwiftDataServer to your Swift package and configure your preferred database backend.
1. Configure the registry
SwiftDataServer is distributed through a private Swift Package Registry. Point Swift Package Manager at the SwiftDataServer scope and log in once with your access token:
swift package-registry set --global --scope SwiftDataServer https://packages.swiftdataserver.com
swift package-registry login https://packages.swiftdataserver.com --token YOUR_TOKEN
The token is stored in your Keychain (or ~/.netrc) and used to authenticate every package fetch. Your token is available in the dashboard after purchasing a license.
2. Package.swift
Reference the package by its registry identity — no URL:
dependencies: [
.package(id: "SwiftDataServer.SDK", from: "1.0.0")
]
Then add the products you need to your target:
targets: [
.target(
name: "App",
dependencies: [
.product(name: "SwiftDataServer", package: "SwiftDataServer.SDK"),
.product(name: "PostgreSQLBackend", package: "SwiftDataServer.SDK"), // or MySQLBackend, SQLiteBackend, RESTBackend
.product(name: "VaporIntegration", package: "SwiftDataServer.SDK"), // 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 |
RESTBackend |
SwiftData-style persistence over any REST API |
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
- Quick Start - Create your first model and run queries
- Vapor Integration - Set up SwiftDataServer with Vapor