> ## Documentation Index
> Fetch the complete documentation index at: https://docs.insforge.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK de Swift para iOS, macOS, tvOS, watchOS

> Instale e inicialice el SDK oficial de Swift de InsForge a través de Swift Package Manager para usar autenticación, base de datos, almacenamiento y funcionalidad en tiempo real en plataformas de Apple.

El SDK de Swift de InsForge proporciona un cliente Swift nativo para interactuar con servicios de InsForge desde aplicaciones iOS, macOS, tvOS y watchOS.

## Instalación

### Swift Package Manager

Add InsForge to your Swift Package Manager dependencies:

```swift theme={null}
dependencies: [
    .package(url: "https://github.com/insforge/insforge-swift.git", from: "0.0.9")
]
```

```swift theme={null}
import InsForge

let insforge = InsForgeClient(
    baseURL: URL(string: "https://your-app.insforge.app")!,
    anonKey: "your-anon-key"
)
```

### Enable Logging (Optional)

For debugging, you can configure the SDK log level and destination:

```swift theme={null}
let options = InsForgeClientOptions(
    global: .init(
        logLevel: .debug,
        logDestination: .osLog,
        logSubsystem: "com.example.MyApp"
    )
)

let insforge = InsForgeClient(
    baseURL: URL(string: "https://your-app.insforge.app")!,
    anonKey: "your-anon-key",
    options: options
)
```

**Log Levels:**

| Level       | Description                                 |
| ----------- | ------------------------------------------- |
| `.trace`    | Most verbose, includes all internal details |
| `.debug`    | Detailed information for debugging          |
| `.info`     | General operational information (default)   |
| `.warning`  | Warnings that don't prevent operation       |
| `.error`    | Errors that affect functionality            |
| `.critical` | Critical failures                           |

**Log Destinations:**

| Destination | Description                                                |
| ----------- | ---------------------------------------------------------- |
| `.console`  | Standard output (print)                                    |
| `.osLog`    | Apple's unified logging system (recommended for iOS/macOS) |
| `.none`     | Disable logging                                            |
| `.custom`   | Provide your own LogHandler factory                        |

<Note>
  Use `.info` or `.error` in production to avoid exposing sensitive data in logs.
</Note>

O agréguelo a través de Xcode:

1. File → Add Packages...
2. Ingrese: `https://github.com/insforge/insforge-swift.git`

### CocoaPods (próximamente)

```ruby theme={null}
pod 'InsForge', '~> 1.0'
```

## Inicio rápido

```swift theme={null}
import InsForge

let insforge = InsForgeClient(
    baseUrl: "https://your-app.insforge.app",
    anonKey: "your-anon-key"
)
```

## Características

* **Base de datos** - Operaciones CRUD de tipo seguro con soporte de Codable
* **Autenticación** - Autenticación con correo electrónico/contraseña y OAuth
* **Almacenamiento** - Carga, descarga y gestión de archivos
* **IA** - Completaciones de chat y generación de imágenes
* **Tiempo real** - Mensajería pub/sub basada en WebSocket
* **Integración de SwiftUI** - Envolturas de propiedades y valores de entorno

## Compatibilidad de plataformas

| Plataforma | Versión mínima |
| ---------- | -------------- |
| iOS        | 15.0+          |
| macOS      | 12.0+          |
| tvOS       | 15.0+          |
| watchOS    | 8.0+           |

## Referencia del SDK

<CardGroup cols={2}>
  <Card title="Database" icon="database" href="/sdks/swift/database">
    CRUD operations with Codable models
  </Card>

  <Card title="Authentication" icon="lock" href="/sdks/swift/auth">
    Sign up, sign in, OAuth, and user management
  </Card>

  <Card title="Storage" icon="cloud-arrow-up" href="/sdks/swift/storage">
    File upload, download, and management
  </Card>

  <Card title="AI" icon="brain" href="/sdks/swift/ai">
    Chat completions and image generation
  </Card>

  <Card title="Realtime" icon="signal-stream" href="/sdks/swift/realtime">
    WebSocket pub/sub messaging
  </Card>
</CardGroup>
