In this section, you will learn how to connect to SurrealDB and run your first query using the Swift SDK.
This guide covers defining a model, connecting to SurrealDB, authenticating, and running your first queries with the Swift SDK. Make sure you have installed the SDK first.
Define a model
The @SurrealModel macro generates SurrealModel conformance, the surrealTable name, and a type-safe Fields namespace used to build predicates.
import SurrealDB
@SurrealModel("person") struct Person: Codable, Sendable { let id: String? let name: String let age: Int }
Connect to the database
Create a client for your endpoint and connect. The HTTP client is the simplest starting point; for live queries you will need the WebSocket client instead.