> ## 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.

# Swift SDK for iOS, macOS, tvOS, watchOS

> Install and initialize the official InsForge Swift SDK via Swift Package Manager to use auth, database, storage, and realtime across Apple platforms.

The InsForge Swift SDK provides a native Swift client for interacting with InsForge services from iOS, macOS, tvOS, and watchOS applications.

## Installation

### 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>

Or add it via Xcode:

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

### CocoaPods (coming soon)

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

## Quick start

```swift theme={null}
import InsForge

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

## Features

* **Database** - Type-safe CRUD operations with Codable support
* **Authentication** - Email/password and OAuth authentication
* **Storage** - File upload, download, and management
* **AI** - Chat completions and image generation
* **Realtime** - WebSocket-based pub/sub messaging
* **SwiftUI Integration** - Property wrappers and environment values

## Platform support

| Platform | Minimum Version |
| -------- | --------------- |
| iOS      | 15.0+           |
| macOS    | 12.0+           |
| tvOS     | 15.0+           |
| watchOS  | 8.0+            |

## SDK reference

<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>
