# Models

Define type-safe models for SurrealDB using the @SurrealModel macro or manual conformance in the Swift SDK.

Models describe the shape of your records and give the SDK the type information it needs for type-safe CRUD operations and [predicates](/docs/reference/swift/concepts/predicates.md).

## The `@SurrealModel` macro

The `@SurrealModel` macro is the recommended way to declare a model. It takes the table name and generates everything the SDK needs:

```swift
import SurrealDB

@SurrealModel("person")
struct Person: Codable, Sendable {
    let id: String?
    let name: String
    let age: Int
}
```

The macro generates:

- `static let surrealTable`, the table name passed to the macro.
- `SurrealModel` conformance, so the type can be used directly with [`select`](/docs/reference/swift/methods/select.md), [`create`](/docs/reference/swift/methods/create.md), [`update`](/docs/reference/swift/methods/update.md), [`upsert`](/docs/reference/swift/methods/upsert.md) and [`delete`](/docs/reference/swift/methods/delete.md).
- A `Fields` namespace for building type-safe predicates such as `Person.Fields.age >= 18`.

## Manual conformance

If you prefer not to use the macro, you can conform to `SurrealModel` manually by declaring the `surrealTable` property:

```swift
struct Article: SurrealModel, Codable, Sendable {
    static let surrealTable = "article"
    let id: String?
    let title: String
}
```

Manual conformance does not generate a `Fields` namespace, so you will need to write [raw predicates](/docs/reference/swift/concepts/predicates.md#raw-predicates) for queries that filter on fields.
